Jump to content

Archived

This topic is now archived and is closed to further replies.

nashyboy

Help Please!!!

Recommended Posts

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>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</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.....?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.