Jump to content


Photo

Help Please!!!


  • Please log in to reply
2 replies to this topic

#1 nashyboy

nashyboy
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 June 2006 - 05:46 PM

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.....?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 June 2006 - 05:59 PM

When testing, it's worth getting into the habit of echoing queries so you can really see what's happening.
$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());

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.
Legend has it that reading the manual never killed anyone.
My site

#3 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 22 June 2006 - 06:07 PM

try calling the variables like this on your add page

$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()); 

you have to do it that way because since php4 superglobals are automaticly turned of in your php.ini

The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users