herghost Posted March 6, 2009 Share Posted March 6, 2009 Hi, can someone please take a look at this and see what I have forgotten? I am getting a parse error on line 68 (which is the last line) I am sure it is just a ; or bracket or something, but I have been staring at it for so long I can not see it! <?php //let's start our session, so we have access to stored data session_start(); include('include/config.php'); $query = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$query) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); //let's create the query $insert_query = "insert into members ( fname, lname, login, password email, ) values ( " . $_SESSION['fname'] . ", " . $_SESSION['lname'] . ", " . $_SESSION['login'] . ", " . $_SESSION['password'] . ", " . $_SESSION['email'] . " )"; //let's run the query mysql_query($insert_query); $insert_query = "insert into members_location ( house, fline, sline, city, county, postcode ) values ( " . $_SESSION['house'] . ", " . $_SESSION['fline'] . ", " . $_SESSION['sline'] . ", " . $_SESSION['city'] . ", " . $_SESSION['county'] . ", " . $_SESSION['postcode'] . " )"; //let's run the query mysql_query($insert_query); ?> Thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted March 6, 2009 Share Posted March 6, 2009 I dont see where you close if(!$db) { Quote Link to comment Share on other sites More sharing options...
herghost Posted March 6, 2009 Author Share Posted March 6, 2009 Thanks Mate, That was it, however for some reason it is not posting any information to the database Thanks for your help in all my threads Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted March 6, 2009 Share Posted March 6, 2009 Add or die (mysql_error()) after your query, it will tell you why the insert failed Quote Link to comment Share on other sites More sharing options...
revraz Posted March 6, 2009 Share Posted March 6, 2009 Remove the last comma in your first query here email, <-- Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 no database protection what so ever not even mysql_real_escape_string() Quote Link to comment Share on other sites More sharing options...
herghost Posted March 6, 2009 Author Share Posted March 6, 2009 Hmm the error I am getting is this: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@getstock.co.uk )' at line 13 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' , , , , )' at line 10 @getstock.co.uk is part of the email address that I have entered to register a user @redarrow = This is not a live site, its on my local server only, any database protection I will add once the site is complete Quote Link to comment Share on other sites More sharing options...
revraz Posted March 6, 2009 Share Posted March 6, 2009 Post the exact email you are trying to enter. Quote Link to comment Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 You need to put a comma here in your first query: password, Quote Link to comment Share on other sites More sharing options...
herghost Posted March 6, 2009 Author Share Posted March 6, 2009 Thanks o both of you: The exact email I am trying to enter is admin@getstock.co.uk: Here is my latest file: <?php session_start(); include('include/config.php'); $query = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$query) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $insert_query = "insert into members ( fname, lname, login, password, email ) values ( " . $_SESSION['fname'] . ", " . $_SESSION['lname'] . ", " . $_SESSION['login'] . ", " . $_SESSION['password'] . ", " . $_SESSION['email'] . " )"; mysql_query($insert_query); echo mysql_errno($query) . ": " . mysql_error($query). "\n"; $insert_query = "insert into members_location ( house, fline, sline, city, county, postcode ) values ( " . $_SESSION['house'] . ", " . $_SESSION['fline'] . ", " . $_SESSION['sline'] . ", " . $_SESSION['city'] . ", " . $_SESSION['county'] . ", " . $_SESSION['postcode'] . " )"; //let's run the query mysql_query($insert_query); echo mysql_errno($query) . ": " . mysql_error($query). "\n"; ?> I seem to be an expert of writing code that does not work Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 Quick example. look at the size off the database field for email it probably to small. <?php //let's start our session, so we have access to stored data session_start(); include('include/config.php'); $query = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$query) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //let's create the query $insert_query = "insert into members ( fname, lname, login, password email, ) values ( " . mysql_real_escape_string($_SESSION['fname']).", " . mysql_real_escape_string($_SESSION['lname']) . ", " . mysql_real_escape_string($_SESSION['login'] ). ", " . mysql_real_escape_string($_SESSION['password']) . ", " . mysql_real_escape_string($_SESSION['email']) . " )"; //let's run the query mysql_query($insert_query)or die(mmysql_error()); $insert_query = "insert into members_location ( house, fline, sline, city, county, postcode ) values ( " . mysql_real_escape_string($_SESSION['house']). ", " . mysql_real_escape_string($_SESSION['fline'] ). ", " . mysql_real_escape_string($_SESSION['sline'] ). ", " . mysql_real_escape_string($_SESSION['city'] ). ", " . mysql_real_escape_string($_SESSION['county']) . ", " . mysql_real_escape_string($_SESSION['postcode'] ). " )"; //let's run the query mysql_query($insert_query)or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted March 6, 2009 Share Posted March 6, 2009 echo $insert_query and paste the results. Quote Link to comment Share on other sites More sharing options...
herghost Posted March 6, 2009 Author Share Posted March 6, 2009 thanks red arrow, I have changed it upto 200 characters from 95, same problem though. I have also attached the files that call this script, its part of a registration form: Step 1: <?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="stylesheet.css" rel="stylesheet" type="text/css"> <title>Untitled Document</title> </head> <body> <div class="twoColElsLt"> <form method="post" action="registration_step2.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <th>First Name </th> <td class="tdback"><input name="fname" type="text" class="textfield" id="fname" /></td> </tr> <tr> <th>Last Name </th> <td class="tdback"><input name="lname" type="text" class="textfield" id="lname" /></td> </tr> <tr> <th width="124">Desired User Name</th> <td class="tdback"><input name="login" type="text" class="textfield" id="login" /></td> </tr> <tr> <th>Password</th> <td class="tdback"><input name="password" type="password" class="textfield" id="password" /></td> </tr> <tr> <th>Email Address </th> <td class="tdback"><input name="email" type="text" class="textfield" id="email" /></td> </tr> <tr> <td> </td> <td class="tdback"><input type="submit" name="Submit" value="Continue Registration" /></td> </tr> </table> </form> </div> </body> </html> and Step 2: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="stylesheet.css" rel="stylesheet" type="text/css"> <title>Untitled Document</title> </head> <body> <?php session_start(); session_register('fname'); session_register('lname'); session_register('login'); session_register('password'); session_register('email'); $_SESSION['fname'] = $_POST['fname']; $_SESSION['lname'] = $_POST['lname']; $_SESSION['login'] = $_POST['login']; $_SESSION['password'] = md5($_POST['password']); $_SESSION['email'] = $_POST['email']; ?> <div class="twoColElsLt"> <form method="post" action="registration_do.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <th>House Name / Number </th> <td class="tdback"><input name="house" type="text" class="textfield" id="house" /></td> </tr> <tr> <th>First Line of Address</th> <td class="tdback"><input name="fline" type="text" class="textfield" id="fline" /></td> </tr> <tr> <th width="124">Second Line of Address</th> <td class="tdback"><input name="sline" type="text" class="textfield" id="sline" /></td> </tr> <tr> <th>City</th> <td class="tdback"><input name="city" type="text" class="textfield" id="city" /></td> </tr> <tr> <th>County </th> <td class="tdback"><input name="county" type="text" class="textfield" id="county" /></td> </tr> <tr> <th>Postcode </th> <td class="tdback"><input name="postcode" type="text" class="textfield" id="postcode" /></td> </tr> <tr> <td> </td> <td class="tdback"><input type="submit" name="Submit" value="Continue Registration" /></td> </tr> </table> </form><?php session_register('house'); session_register('fline'); session_register('sline'); session_register('city'); session_register('county'); session_register('postcode'); ?> </body> </html> This is getting bloody annoying! Quote Link to comment Share on other sites More sharing options...
revraz Posted March 6, 2009 Share Posted March 6, 2009 For page 2, you need to have session_start(); before any output to the browser. Your session variables are not coming over because you are getting a HEADER error. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 you also dont need session_register(what_ever) it depreciated use $_SESSION['what_ever']=$_POSt['what_ever'] convert the code then delete the old session_register() function. <?php session_start(); ?> //CORRECTED. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="stylesheet.css" rel="stylesheet" type="text/css"> <title>Untitled Document</title> </head> <body> <?php //session_start(); WRONG session_register('fname'); session_register('lname'); session_register('login'); session_register('password'); session_register('email'); $_SESSION['fname'] = $_POST['fname']; $_SESSION['lname'] = $_POST['lname']; $_SESSION['login'] = $_POST['login']; $_SESSION['password'] = md5($_POST['password']); $_SESSION['email'] = $_POST['email']; ?> <div class="twoColElsLt"> <form method="post" action="registration_do.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <th>House Name / Number </th> <td class="tdback"><input name="house" type="text" class="textfield" id="house" /></td> </tr> <tr> <th>First Line of Address</th> <td class="tdback"><input name="fline" type="text" class="textfield" id="fline" /></td> </tr> <tr> <th width="124">Second Line of Address</th> <td class="tdback"><input name="sline" type="text" class="textfield" id="sline" /></td> </tr> <tr> <th>City</th> <td class="tdback"><input name="city" type="text" class="textfield" id="city" /></td> </tr> <tr> <th>County </th> <td class="tdback"><input name="county" type="text" class="textfield" id="county" /></td> </tr> <tr> <th>Postcode </th> <td class="tdback"><input name="postcode" type="text" class="textfield" id="postcode" /></td> </tr> <tr> <td> </td> <td class="tdback"><input type="submit" name="Submit" value="Continue Registration" /></td> </tr> </table> </form><?php session_register('house'); session_register('fline'); session_register('sline'); session_register('city'); session_register('county'); session_register('postcode'); ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 NEVER use short tags.... Quote Link to comment Share on other sites More sharing options...
herghost Posted March 6, 2009 Author Share Posted March 6, 2009 Thanks have coreected that error: Rerun login script and this is the output: insert into members ( fname, lname, login, password, email ) values ( dave, dave, dave, 1610838743cc90e3e4fdda748282d9b8, admin@getstock.co.uk )insert into members_location ( house, fline, sline, city, county, postcode ) values ( , , , , , ) Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 convert to new way, then use this on the insert page if the user submits ok. look at the code that is going into the database then repeat with new variables that it. <?php session_register('house'); session_register('fline'); session_register('sline'); session_register('city'); session_register('county'); session_register('postcode'); ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 look at this to the code i just posted lot off diffrence. convert the other code to the same new format. in php 5 we now use post ok. <?php //from here session_register('fname'); session_register('lname'); session_register('login'); session_register('password'); session_register('email'); // to here not needed. // this is the correct way in php5 creating the session also registers the session.. $_SESSION['fname'] = $_POST['fname']; $_SESSION['lname'] = $_POST['lname']; $_SESSION['login'] = $_POST['login']; $_SESSION['password'] = md5($_POST['password']); $_SESSION['email'] = $_POST['email']; ?> DO THE SAME WITH THIS <?php session_register('house'); session_register('fline'); session_register('sline'); session_register('city'); session_register('county'); session_register('postcode'); ?> Quote Link to comment Share on other sites More sharing options...
herghost Posted March 6, 2009 Author Share Posted March 6, 2009 Notice: Undefined index: house in C:\wamp\www\cvsite\registration_step2.php on line 67 Notice: Undefined index: fline in C:\wamp\www\cvsite\registration_step2.php on line 68 Notice: Undefined index: sline in C:\wamp\www\cvsite\registration_step2.php on line 69 Notice: Undefined index: city in C:\wamp\www\cvsite\registration_step2.php on line 70 Notice: Undefined index: county in C:\wamp\www\cvsite\registration_step2.php on line 71 Notice: Undefined index: postcode in C:\wamp\www\cvsite\registration_step2.php on line 72 I get this if I use your code sample. Thanks for taking the time to help me with this, I am determined to get this working! EDIT Solved this by moving the $_SESSION['house'] = $_POST['house']; etc onto the DO script. The output of the echo query and errors is now as follows: insert into members ( fname, lname, login, password, email ) values ( Dave, Account, adminyt, 81dc9bdb52d04dc20036dbd8313ed055, admin )1054: Unknown column 'fname' in 'field list' 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'street, andtown, Norfolk, Norfok, NR0 000 )' at line 11 insert into members_location ( house, fline, sline, city, county, postcode ) values ( 7, A street, andtown, Norfolk, Norfok, NR0 000 ) Quote Link to comment Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 I don't see where you assign these sessions values? session_register('house'); session_register('fline'); session_register('sline'); session_register('city'); session_register('county'); session_register('postcode'); * You don't need the session_register you just need something like you did with the other group of sessions: $_SESSION['fname'] = $_POST['fname']; $_SESSION['lname'] = $_POST['lname']; $_SESSION['login'] = $_POST['login']; $_SESSION['password'] = md5($_POST['password']); $_SESSION['email'] = $_POST['email']; Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 do the rest then test <?php $_SESSION['house']=$_POST['house'];// do the rest as shown this is //for the form to post the variable to declare it, and to register a session //for the variable of house. session_register('fline'); session_register('sline'); session_register('city'); session_register('county'); session_register('postcode'); ?> Quote Link to comment Share on other sites More sharing options...
herghost Posted March 6, 2009 Author Share Posted March 6, 2009 Sorry edited my last post as you was replying, please see my last post Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 post your current code your repeating something wrongly, the database error tells me that. Quote Link to comment Share on other sites More sharing options...
herghost Posted March 6, 2009 Author Share Posted March 6, 2009 Page 2: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="stylesheet.css" rel="stylesheet" type="text/css"> <title>Untitled Document</title> </head> <body> <?php $_SESSION['firstname'] = $_POST['firstname']; $_SESSION['lastname'] = $_POST['lastname']; $_SESSION['login'] = $_POST['login']; $_SESSION['passwd'] = md5($_POST['passwd']); $_SESSION['email'] = $_POST['email']; ?> <form method="post" action="registration_do.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <th>House Name / Number </th> <td class="tdback"><input name="house" type="text" class="textfield" id="house" /></td> </tr> <tr> <th>First Line of Address</th> <td class="tdback"><input name="fline" type="text" class="textfield" id="fline" /></td> </tr> <tr> <th width="124">Second Line of Address</th> <td class="tdback"><input name="sline" type="text" class="textfield" id="sline" /></td> </tr> <tr> <th>City</th> <td class="tdback"><input name="city" type="text" class="textfield" id="city" /></td> </tr> <tr> <th>County </th> <td class="tdback"><input name="county" type="text" class="textfield" id="county" /></td> </tr> <tr> <th>Postcode </th> <td class="tdback"><input name="postcode" type="text" class="textfield" id="postcode" /></td> </tr> <tr> <td> </td> <td class="tdback"><input type="submit" name="Submit" value="Continue Registration" /></td> </tr> </table> </form> </body> </html> Do code <?php session_start(); $_SESSION['house'] = $_POST['house']; $_SESSION['fline'] = $_POST['fline']; $_SESSION['sline'] = $_POST['sline']; $_SESSION['city'] = $_POST['city']; $_SESSION['county'] = $_POST['county']; $_SESSION['postcode'] = $_POST['postcode']; include('include/config.php'); $query = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$query) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $insert_query = "insert into members ( firstname, lastname, login, passwd, email ) values ( " . $_SESSION['firstname'] . ", " . $_SESSION['lastname'] . ", " . $_SESSION['login'] . ", " . $_SESSION['passwd'] . ", " . $_SESSION['email'] . " )"; mysql_query($insert_query); echo $insert_query; echo mysql_errno($query) . ": " . mysql_error($query). "\n"; $insert_query = "insert into members_location ( house, fline, sline, city, county, postcode ) values ( " . $_SESSION['house'] . ", " . $_SESSION['fline'] . ", " . $_SESSION['sline'] . ", " . $_SESSION['city'] . ", " . $_SESSION['county'] . ", " . $_SESSION['postcode'] . " )"; //let's run the query mysql_query($insert_query); echo mysql_errno($query) . ": " . mysql_error($query). "\n"; echo $insert_query; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.