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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vars from php to mysql don't change 1

Status
Not open for further replies.

dropoutuser

Programmer
Feb 25, 2005
9
US
I'm using PHP and MySql. I hard coded in some information that I wanted to be sent to a table in MySql and it worked. I changed the variables and ran it again but the same values from the first time were entered. I then set up some variables and pulled the information from a form the user fills out and still it inputs the data from the first time. Any input would be appreciated.

Thanks
 
Can you give a little more detail? A segment of the code that worked and a similar part of the code that failed would be a good starting point.
 
The code I used that worked was:

<?php
$conn = mysql_connect("localhost", "root",);
mysql_select_db("test", $conn);
$sql="INSERT INTO userlog values("foo1", "foo2", "foo3", "foo4")";
mysql_query($sql,$conn);
?>

Then I changed the information that was being sent to the database but it still added the information in the code above.

Then I set up variables to add the info instead of hardcoding it using:

$f_name=$_POST[f_name];
$l_name=$_POST[l_name];

and so on. Even then it still added the information that was hardcoded in the first time. Any ideas what the problem could be or what I'm doing wrong?

Thanks
 
What did you change your SQL statement to?

There are a few things in your code that you should take care of immediately:
1) Don't connect to your MySQL server as the root user. Follow the instructions MySQL gives about setting up other users to minimize vulnerabilities.

2) Add error checking to your MySQL queries. See faq434-3850
 
The only thing in the code that I changed the second time was the information passed to the database in the sql statement. For example changed foo1, foo2, foo3, foo4 to foo5, foo6, foo7, foo8.
 
Do you mind just posting the relevant code?
I see that you appear to understand the principle, the code would show me more to find out what's happening. The foo's really don't help.
 
All of my code is posted here exactly except instead of the foos I had different information: joe, smith, user1, pass. Then changed it to john, doe, user2, pass. Trying to add users to a database.
 
How are you executing the code?

Suggestion:
Code:
<?php
echo "Execution time :'.date("F j, Y, g:i a"); 
$conn = mysql_connect("localhost", "root",);
mysql_select_db("test", $conn);
$sql="INSERT INTO userlog values("foo1", "foo2", "foo3", "foo4")";
mysql_query($sql,$conn) OR die('Error: '.mysql_error().' '.$sql);
?>

If you execute the code and the changes don't show then the file that is executed hasn't changed. Could be an upload problem, or saving the file in the right spot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top