nashyboy Posted June 22, 2006 Share Posted June 22, 2006 Hi, this is probably something really simple yet i cannot work out the problem. I used php briefly about 5 years ago but have since forgotten it appears most of the basics!Simple thing really - adding to table is not working. Probably something really stupid that im doing wrong but please see below....This is the form code.<form action="added_user.php" method="post"> <table width="600" border="0" cellspacing="2" cellpadding="2"> <tr> <td width="138">ID (hidden)</td> <td width="462"><input name="id" type="hidden"></td> </tr> <tr> <td>Firstname</td> <td><input name="firstname" type="text" size="30" maxlength="80"></td> </tr> <tr> <td>Surname</td> <td><input name="surname" type="text" size="30" maxlength="80"></td> </tr> <tr> <td>Email</td> <td><input name="email" type="text" size="30" maxlength="80"></td> </tr> <tr> <td>Password</td> <td><input name="password" type="text" size="30" maxlength="20"></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><input type="reset" name="Reset" value="Reset"> <input name="Submit" type="submit" id="Submit" value="Submit"></td> </tr> </table></form>And this is the added to page....<?php include("login_details.inc");mysql_connect ($dbhost, $dbuser, $dbpass) or die (mysql_error()); //Connects to database mysql_select_db ($dbname) or die (mysql_error()); //Selects your database mysql_query("INSERT INTO users (id, firstname, surname, email, password) VALUES('$id', '$firstname', '$surname' , '$email' , '$password' ) ") or die(mysql_error()); mysql_query($query); mysql_close(); ?>All that happens is it submits and i get a blank page. Nothing gets added to the table.Can someone help.....? Quote Link to comment https://forums.phpfreaks.com/topic/12656-help-please/ Share on other sites More sharing options...
AndyB Posted June 22, 2006 Share Posted June 22, 2006 When testing, it's worth getting into the habit of echoing queries so you can really see what's happening.[code]$query = "INSERT INTO users (id, firstname, surname, email, password) VALUES('$id', '$firstname', '$surname' , '$email' , '$password' )";echo $query. "<br/>";$result = mysql_query($query) of die("Error: ". mysql_error());[/code]Looking over the code, it seems you expect register_globals to be ON (which is NOT the default setting). If no values are actually being passed by the form - as you'll see when you echo the query - then you need to abstract data passed from the form using an appropriate syntax rather than simply expecting them globally. Quote Link to comment https://forums.phpfreaks.com/topic/12656-help-please/#findComment-48546 Share on other sites More sharing options...
shortj75 Posted June 22, 2006 Share Posted June 22, 2006 try calling the variables like this on your add page[code]$id=$_POST['id'};$firstname=$_POST['firstname'];$surname=$_POST['surname'];$email=$_POST['email'];$password=$_POST['password'];$query=mysql_query("INSERT INTO users (id, firstname, surname, email, password) VALUES('$id', '$firstname', '$surname' , '$email' , '$password' ) ");mysql_query($query)or die(mysql_error()); [/code]you have to do it that way because since php4 superglobals are automaticly turned of in your php.ini Quote Link to comment https://forums.phpfreaks.com/topic/12656-help-please/#findComment-48549 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.