cshong00 Posted June 2, 2007 Share Posted June 2, 2007 Hi, I'm wondering if I could get some help on an issue I'm having with a site that I'm on. I have two pages. The first page has an HTML form (nothing fancy, just some input boxes and a submit button). On the second page I have this code: <?php $contentid = $_POST["contentid"]; if ($contentid == "") {$contentid = 0;} $contenttypeid = $_POST["contenttypeid"]; $title = $_POST["title"]; $subtitle = $_POST["subtitle"]; $body = $_POST["body"]; $SQL = "INSERT INTO em_content (ContentTypeID, UserID, Title, Subtitle, Body, DateAdded) VALUES (" . $contenttypeid . ", 1, '" . $title . "', '" . $subtitle . "', '" . $body . "', CURRENT_TIMESTAMP)"; $con = mysql_connect("localhost","kccdenve","kccit1"); mysql_select_db("kccdenve_km", $con); mysql_query($SQL); if (!mysql_query($SQL,$con)){ die('Error: ' . mysql_error() . '<br/><br/>' . $SQL); } mysql_close($con); echo "done..."; ?> As you can see I grab the items in the $_POST, set them to variables and generate an INSERT statement. I then connect to my DB and run the INSERT statement using mysql_query(). The problem is, after the INSERT statement runs, I look at the em_content table that it was supposed to make the INSERT to, and there are two rows of the exact same data. I have an auto incrementing ID set up as the PK of the em_content table so the value of that column is different but otherwise the two rows are exactly the same. The code above is ALL the code I have on the second page. I stripped everything else out to try to isolate the issue but in the end, it still inserts the row twice. I obviously need it to just insert once. Has anyone run into this issue before? If so pleeeeaaase help! Quote Link to comment https://forums.phpfreaks.com/topic/53957-solved-double-row-insert-issue-with-php-and-mysql/ Share on other sites More sharing options...
bubblegum.anarchy Posted June 2, 2007 Share Posted June 2, 2007 mysql_query($SQL); // THE DATA IS INSERTED HERE if (!mysql_query($SQL,$con)){ // THE DATE IS ALSO INSERTED HERE die('Error: ' . mysql_error() . '<br/><br/>' . $SQL); } Quote Link to comment https://forums.phpfreaks.com/topic/53957-solved-double-row-insert-issue-with-php-and-mysql/#findComment-266758 Share on other sites More sharing options...
cshong00 Posted June 2, 2007 Author Share Posted June 2, 2007 n00b mistake... Thanks bubblegum, it worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/53957-solved-double-row-insert-issue-with-php-and-mysql/#findComment-266964 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.