Page 1 of 1

Insert into MySQL not working

Posted: Sun Mar 23, 2003 8:49 pm
by AlphaWolf
Hello,
I am new to PHP and looking for help.

I have a form that posts data to the code below to do an insert. Part of the form page also checks to see if this record all ready exists, if it does then it performs an update instead of an insert.

I am getting a mysql_error code of 0 which I thought meant everything was ok, yet I don't get any records in the db. So now I am confused.

any help would be appreciated.

The code to insert or update the DB is as follows:

Code: Select all

// Make Connection to the DB 

$conn=mysql_connect("localhost","admin","adm1n03"); 
mysql_select_db("wedding_db",$conn); 


if($nr == "no"){
echo "It states nr is no.";
echo "Looking at doing an update on the record here...";
$mysql_query = "UPDATE bride set gatekeeper_id = $gatekeeper_id, fname=$fname, mname=$mname, lname=$lname, city_born=$city_born, state_born=$state_born, date_born=$date_born, current_job=$current_job, img1=$img1, img1_text=$img1_text, img2=$img2, img2_text=$img2_text, img3=$img3, img3_text=$img3_text";
 echo mysql_errno() . ": " . mysql_error() . "\n";

}
else{
echo "It states nr is yes.";
echo "Looking at doing an insert into the db here...";
$mysql_query = "INSERT INTO bride (gatekeeper_id, fname, mname, lname, city_born, state_born, date_born, current_job, img1, img1_text, img2, img2_text, img3, img3_text) VALUES ('$gatekeeper_id', '$fname', '$mname', '$lname', '$city_born', '$state_born', '$date_born', '$current_job', '$img1'.''$img1_text', '$img2', '$img2_text', '$img3', '$img3_text')";
 echo mysql_errno() . ": " .  mysql_error() . "\n";

}
	
				
include ("footer.html");
?>
With mysql_error() I get zero. Yet I get no records added to the DB.

Any help would be appreciated. Thanks!
Jeff

Posted: Sun Mar 23, 2003 11:26 pm
by Stoker
you are assigning a string to the variable $mysql_query ...

try mysql_query('INSERT .... etc '); instead, or just add
$result = mysql_query($mysql_query);


... another thing, yoy don't have much security there, has the data been validated?

Thank You

Posted: Wed Mar 26, 2003 1:35 pm
by AlphaWolf
Thank you for your response. I see what you are saying now. I have done some additional reading on this as well and it makes sense what I was doing wrong. I will give it a try.

Thanks for your help.

I have not started looking at anything in terms of security yet as this is just in a development environment unaccessible to the outside world. Thanks again - I appreciate the help.

:D