Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text box information between forms 3

Status
Not open for further replies.

mrobinson

MIS
Oct 11, 2002
36
GB
i have set up my system with the apach server, mysql and php4.
I have followed various tutorials to set it up and test it all. However when i create a database and then try to add information to it via a form it updates the table but with blank entries where the was text entered. I then tried doing it so the data entered would be displayed on another page but it doesn't appear there either, it is just blank. Due to me downloading various tutorials and trying them using cut and paste and keep getting the same problem im pretty sure the code is ok.
Could anyone please help and tell me which possible setting needs changing

Thanks
 
the php form i used is as follows:

<html>

<body>



<?php



if ($submit) {

// process form

$db = mysql_connect(&quot;localhost&quot;, &quot;root&quot;);

mysql_select_db(&quot;mydb&quot;,$db);

$sql = &quot;INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')&quot;;

$result = mysql_query($sql);

echo &quot;Thank you! Information entered.\n&quot;;

} else{



// display form



?>



<form method=&quot;post&quot; action=&quot;<?php echo $PHP_SELF?>&quot;>

First name:<input type=&quot;Text&quot; name=&quot;first&quot;><br>

Last name:<input type=&quot;Text&quot; name=&quot;last&quot;><br>

Address:<input type=&quot;Text&quot; name=&quot;address&quot;><br>

Position:<input type=&quot;Text&quot; name=&quot;position&quot;><br>

<input type=&quot;Submit&quot; name=&quot;submit&quot; value=&quot;Enter information&quot;>

</form>



<?php



} // end if



?>



</body>



</html>

The mysql seems to be working as i can insert information directly with SQL and the php can read information from the tables and display it. Hope you can help
 
Big chance that Register Globals is turned off. In that case your form variables are available in $_POST or $_GET. Try putting this before your query.

$first = $_POST['first'];
$last = $_POST['last'];
etc.
 
Some advice:

1. Set a password for MySQL root user and create a new user for your Web activities. You might work locally now, but you don't want to keep the door open like that. There is a whole chapter about this in the MySQL manual (
2. Read over the register globals chapter in the PHP manual (
 
Take a look to herman75's post, he hit it..

1. $sql = &quot;INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')&quot;;

if you have register global off yo must have before the line:

$first=$_POST['first'];
$last=$_POST['last'];
$address=$_POST['address'];
$position=$_POST['position'];

2. try always to use &quot;or die&quot; in the mysql_query function:

$result = mysql_query($sql) or die (&quot;Error:&quot;.mysql_error());

so, if you have a Mysql error, you will know it.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top