desert_gold_hound Posted March 26, 2009 Share Posted March 26, 2009 I cant figure out why this will not put the PhoneType or PhoneNumber in data base. If I hard code the number or type instead of $_POST[] it puts it into the data base no problem. So far its putting in Null for the type and 0 for the number. Here is HTML page. <html> <head> <title>New Customer</title> </head> <body> <form action="newcustomer.php" method="post"> <h1 align="center">New Customer Forum</h1> <br /><br /> <h4>Customer Information</h4> Firstname: <input name="firstname" size="30" type="text" /> Last Name: <input name="lastname" size="30" type="text" /> <br /><br /> Address: <input name="address" size="77" type="text" /> <br /><br /> City: <input name="city" size="30" value="Lake Havasu" type="text" /> State: <input name="state" size="5" value="AZ" type="text" /> Zip: <input name="zip" size="10" value="86403" type="text" /> <br /><br />Type of Phone: <input name="phonetype" type="text" /> Phone Number: <input name="phonenumb" type="text" /> <br /><br /> // END CUSTOMER INFO <h4>Pet Information*</h4> Name: <input name="petname" type="text" /> Breed: <input name="breed" type="text" /> <!-- Name: <input name="petname" type="text" />Type: <select name="type"> <option value="dog">Dog</option> <option value="cat">Cat</option> <option value="Other">Other</option> </select> Breed: <input name="breed" type="text" /> Age: <input name="age" size="4" type="int" /> <br /><br /> Shots Up To Date: <input name="shots" value="yes" type="radio" /> Yes <input type="radio" /> No <br /><br /> Medical History:<br /> <textarea name="medical" rows="5" cols="70"></textarea> <br /><br /> * --> <input type="submit" /> </form> <p><span style="color: red;">*</span> Required. <br />** More may be added after creation of account.</p> </body> </html> Here is PHP page <?php $con = mysql_connect("PRIVET", "PRIVET", "PRIVET"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("groomingCustomer", $con); // Insert Customer $sql="INSERT INTO Customer (FirstName, LastName, Address, City, State, Zip) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[address]','$_POST[city]','$_POST[state]','$_POST[zip]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Customer = 1 record added"; $lastID = mysql_insert_id(); //Insert Phone $sql="INSERT INTO Phone (PhoneType, Number, CustomerID) VALUES ('$_POST[phonetype]','$_POST[phonenumb]','$lastID')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; //Insert Pet $sql="INSERT INTO Pet (Name, Breed, CustomerID) VALUES ('$_POST[petname]','$_POST[breed]','$lastID')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Pet = 1 record added"; echo "<br /><br /><h1> CustomerID = " . $lastID . "</h1>"; mysql_close($con) ?> WHAT IS WRONG? I have built the another just for the phone and everything works grate on that. Link to comment https://forums.phpfreaks.com/topic/151305-solved-i-am-getting-flustered/ Share on other sites More sharing options...
kittrellbj Posted March 26, 2009 Share Posted March 26, 2009 I would recommend turning your $_POST's into $variables before placing them in the SQL entry. Link to comment https://forums.phpfreaks.com/topic/151305-solved-i-am-getting-flustered/#findComment-794782 Share on other sites More sharing options...
AdRock Posted March 26, 2009 Share Posted March 26, 2009 And you POST should have quotes like $_POST['petname'] etc Link to comment https://forums.phpfreaks.com/topic/151305-solved-i-am-getting-flustered/#findComment-794783 Share on other sites More sharing options...
MadTechie Posted March 26, 2009 Share Posted March 26, 2009 I would recommend turning your $_POST's into $variables before placing them in the SQL entry. Why ? and whos we? theirs not point redefine all the variables! this should work $sql="INSERT INTO Phone (PhoneType, Number, CustomerID) VALUES ('{$_POST['phonetype']}','{$_POST['phonenumb']}','$lastID')"; But this is safer! $sql=sprintf("INSERT INTO Phone (PhoneType, Number, CustomerID) VALUES ('%s','%s',%d)", mysql_real_escape_string($_POST['phonetype']), mysql_real_escape_string($_POST['phonenumb']), $lastID); Link to comment https://forums.phpfreaks.com/topic/151305-solved-i-am-getting-flustered/#findComment-794787 Share on other sites More sharing options...
desert_gold_hound Posted March 27, 2009 Author Share Posted March 27, 2009 OK This is weired. I had to get offline and do some stuff right after I asked this question and I tested when I got back on and it worked without any mods. I don't know what happened I have closed pages, emptied internet stuff (cookies, history) and I just leave and come back and WAHLA IT WORKS. Thanks for the replies I will be looking them over again Thank You. Link to comment https://forums.phpfreaks.com/topic/151305-solved-i-am-getting-flustered/#findComment-794896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.