Help on how to insert data into two different tables? – PHP

  php

Q(Question):

Hi,

I am trying to insert form data into two tables in my database but I keep getting this error:

Parse error: syntax error, unexpected T_STRING in /websites/123reg/LinuxPackage21/fo/ur/wa/fourwaysdp.co.uk/public_html/process.php on line 18

What am I doing wrong?


<?php
$dbhost="";
$dbuser="";
$dbpass="";
$dbname="";
$con=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to the database:' . mysql_error());
$mysql_select_db($dbname, $con);
$sql="INSERT INTO job_title (msg_id,title)
VALUES (' ', '$_POST[title]')";
mysql_query($sql);
$lastid=mysql_insert_id();
$sql2=INSERT INTO job_location (msg_id,location,msg)
VALUES ($lastid, ' ', '$_POST[location]','$_POST[msg]')";
//msg_id & msg_id are auto-incrementing primary keys
mysql_query($sql2);
mysql_close($con);
?>
<html>
<body>
<a href="maybe.php">Back</a>
</body
</html>

A(Answer):

youÂ’re missing the opening double quotation mark on line #18.

A(Answer):

I have now added the " but I get this error message now:

Fatal error: Function name must be a string in /websites/123reg/LinuxPackage21/fo/ur/wa/fourwaysdp.co.uk/public_html/todayprocess.php on line 9


<?php
$dbhost="";
$dbuser="";
$dbpass="";
$dbname="";
$con=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to the database:' . mysql_error());
$mysql_select_db[$dbname];
$sql="INSERT INTO job_tit (msg_id,title)
VALUES (' ', '$_POST[title]')";
mysql_query($sql);
$lastid=mysql_insert_id();
$sql2="INSERT INTO job_loc (msg_id,location,msg)
VALUES ($lastid, ' ', '$_POST[location]','$_POST[msg]')";
//msg_id & msg_id are auto-incrementing primary keys
mysql_query($sql2);
mysql_close($con);
?>
<html>
<body>
<a href="today.php">Back</a>
</body
</html>

A(Answer):

functions are called without $ and with parentheses, not square brackets.

A(Answer):

Ah thank you,

I have two search boxes at the bottom of fourwaysdp.co.uk/today.php

I want to FULL JOIN some of the columns from the tables I have created (job_tit, job_loc)
I have written the code but it still doesnt show any results
What have I done wrong?


<?php
if(strlen(trim($_POST['search'])) > 0) {
//all of your php code for the search
$search = "%" . $_POST["search"] . "%";
mysql_connect ("", "", "");
mysql_select_db ("");
if (!empty($_POST["search_string"]))
{
}
$query = "SELECT job_tit.title, job_loc.location, job_loc.msg
FROM job_tit
FULL JOIN job_loc
ON job_tit.msg_id=job_loc.msg_id";
$result = mysql_query ($query);
if ($result) {
while ($row = mysql_fetch_array ($result)) {
echo "<br>$row[0]<br/>";
echo $row[1];
echo "<br>$row[2]<br/><br><br/>";
}
}
}
?>
</body>
</html>

A(Answer):

FULL JOIN doesn’t look like a valid command, cf. MySQL manual

A(Answer):

Ok I removed the FULL and now results show up BUT no matter what data I enter all the data from my tables show up. How do I filter it so only ones that match what I have typed in the search box

http://fourwaysdp.co.uk/today.php

LEAVE A COMMENT