473,376 Members | 1,086 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,376 software developers and data experts.

Help on how to insert data into two different tables?

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?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbhost="";
  3. $dbuser="";
  4. $dbpass="";
  5. $dbname="";
  6.  
  7. $con=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to the database:' . mysql_error());
  8.  
  9. $mysql_select_db($dbname, $con);
  10.  
  11. $sql="INSERT INTO job_title (msg_id,title) 
  12.          VALUES (' ', '$_POST[title]')";
  13.  
  14. mysql_query($sql);
  15.  
  16. $lastid=mysql_insert_id();
  17.  
  18. $sql2=INSERT INTO job_location (msg_id,location,msg)
  19.               VALUES ($lastid, ' ', '$_POST[location]','$_POST[msg]')";
  20.  
  21. //msg_id & msg_id are auto-incrementing primary keys 
  22.  
  23. mysql_query($sql2);
  24.  
  25. mysql_close($con);
  26.  
  27. ?>
  28. <html>
  29. <body>
  30. <a href="maybe.php">Back</a>
  31. </body
  32. </html>
  33.  
Aug 19 '11 #1
6 2242
Dormilich
8,658 Expert Mod 8TB
you’re missing the opening double quotation mark on line #18.
Aug 19 '11 #2
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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbhost="";
  3. $dbuser="";
  4. $dbpass="";
  5. $dbname="";
  6.  
  7. $con=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to the database:' . mysql_error());
  8.  
  9. $mysql_select_db[$dbname];
  10.  
  11. $sql="INSERT INTO job_tit (msg_id,title) 
  12.          VALUES (' ', '$_POST[title]')";
  13.  
  14. mysql_query($sql);
  15.  
  16. $lastid=mysql_insert_id();
  17.  
  18. $sql2="INSERT INTO job_loc (msg_id,location,msg)
  19.               VALUES ($lastid, ' ', '$_POST[location]','$_POST[msg]')";
  20.  
  21. //msg_id & msg_id are auto-incrementing primary keys 
  22.  
  23. mysql_query($sql2);
  24.  
  25. mysql_close($con);
  26.  
  27. ?>
  28. <html>
  29. <body>
  30. <a href="today.php">Back</a>
  31. </body
  32. </html>
  33.  
Aug 19 '11 #3
Dormilich
8,658 Expert Mod 8TB
functions are called without $ and with parentheses, not square brackets.
Aug 19 '11 #4
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?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(strlen(trim($_POST['search'])) > 0) {
  3. //all of your php code for the search
  4.  
  5.    $search = "%" . $_POST["search"] . "%";
  6.  
  7.  
  8.   mysql_connect ("", "", "");
  9.   mysql_select_db ("");
  10.  if (!empty($_POST["search_string"])) 
  11.    { 
  12.  
  13.    }  
  14.   $query = "SELECT job_tit.title, job_loc.location, job_loc.msg
  15.   FROM job_tit
  16.   FULL JOIN job_loc
  17.   ON job_tit.msg_id=job_loc.msg_id";
  18.  
  19.  
  20.  
  21.   $result = mysql_query ($query);
  22.   if ($result) {
  23.     while ($row = mysql_fetch_array ($result)) {
  24.       echo "<br>$row[0]<br/>";
  25.       echo $row[1];
  26.       echo "<br>$row[2]<br/><br><br/>";
  27.  
  28.     }
  29.   }
  30. }
  31. ?>
  32. </body>
  33. </html>
  34.  
Aug 19 '11 #5
Dormilich
8,658 Expert Mod 8TB
FULL JOIN doesn’t look like a valid command, cf. MySQL manual
Aug 19 '11 #6
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
Aug 19 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
7
by: Paolo | last post by:
I know I should not be doing this, but I find it very useful. I have a database in Access which stores data for a small company. Sometimes we need to add similar information to different tables....
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
9
by: Hi5 | last post by:
Hi, Any Idea how, I can make an Insert statement to insert data into 6 different tables, that are all holding all data of my database? Is there any example? I would be grateful if you could...
1
by: Pratik Gupte | last post by:
I have created a database in .mdf format, but I am unable to insert data into its tables. Can anybody help how to insert data using ASP.Net 2.0 using SQL Server 2005 Express edition in windows...
4
by: satish | last post by:
Values of two columns in two different tables--presentation using select Hi Everyone, i have two tables in the database . One is called address table and one is adressPhone Table. Below...
5
by: narendrareddy | last post by:
Hi , assume a flat file name emp.txt contains the following data 10000100001 narendranathreddy tallapireddy 01-01-2007 male 10000100002 ravindranathreddy tallapireddy 01-01-2008 male...
5
by: RomeoX | last post by:
Hi everybody actually I need your help in fixing my code. Actually I have a library system that can be applied in university or any school and I'm stucking in a page that for loan student book. I...
2
by: shivasusan | last post by:
Hi! I have two tables in my database (userinfo, logininfo) - userinfo table has five fields (uname, pws, con_pws, squest, sans) - logininfo table has then six fields (fname,lname,dob,add1,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.