pinangsia Posted September 5, 2006 Share Posted September 5, 2006 Calling all experts, as a newbie, i'm trying to insert data from a html form to mysql, please see my below php scripts. i'm using php5.0.2, mysql 4.1 and apache 2.0.52on script1, its always telling me that i have not entered all data, if i get rid of this lineif (!$isbn || !$author || !$title || !$price),it actually works, but nothing in mysql database, just empty row.same on script2 only empty rows.please let me know what i did wrong.all feedback is very very much appreciated.script1==>[code]<html><head><title> Book entry homepage</title></head><body><h1> Book Entry Results</h1><?php//create short var names$isbn = $HTTP_POST_VARS['isbn'];$author = $HTTP_POST_VARS['author'];$title = $HTTP_POST_VARS['title'];$price = $HTTP_POST_VARS['price'];if (!$isbn || !$author || !$title || !$price){ echo 'You have not entered all required details <br />'.'Please go back and try again.'; exit;}$isbn = addslashes($isbn);$author = addslashes($author);$title = addslashes($title);$price = doubleval($price);@ $db = mysql_pconnect ('localhost', 'root', 'password');if (!$db){ echo 'cannot connect to database try again later'; exit;}mysql_select_db ('testaj');$query = "INSERT INTO books VALUES ('".$isbn."', '".$author."', '".$title."', '".$price."')";$result = mysql_query($query);if ($result) echo mysql_affected_rows().'book entered into database.';?></body></html>[/code]script 2==>[code]<?//create short var names$firstName = $_POST['firstName'];$lastName = $_POST['lastName'];/*if ($firstName or $lastName ){ echo 'You have not entered all required details <br />'.'Please go back and try again.'; exit;}$firstName = addslashes($firstName);$lastName = addslashes($lastName);*/@ $db = mysql_pconnect ('localhost', 'root', 'password');if (!$db){ echo 'cannot connect to database try again later'; exit;}mysql_select_db ('demo');$query = "INSERT INTO members (firstName, lastName) VALUES ('".$firstName."', '".$lastName."')";$result = mysql_query ($query);if ($result) echo mysql_affected_rows() .'name entered into database.';?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 5, 2006 Share Posted September 5, 2006 Can you post the file/script that has the form used to enter data, please? Quote Link to comment Share on other sites More sharing options...
pinangsia Posted September 5, 2006 Author Share Posted September 5, 2006 Thanks in advance andyB,[code]<html><head> <title> New Book Entry </title></head><body><h1> Book Entry </h1><form action= "insert_book.php" method= "post"> <table border="0"> <tr> <td>ISBN</td> <td><input type="text" name "isbn" maxlength="13" size="13"><br /></td> </tr> <tr> <td>Author</td> <td><input type="text" name "author" maxlength="30" size="30"><br /></td> </tr> <tr> <td>Title</td> <td><input type="text" name "title" maxlength="60" size="30"><br /></td> </tr> <tr> <td>Price %body%lt;/td> <td><input type="text" name "price" maxlength="7" size="7"><br /></td> </tr> <tr> <td colspan="2"><input type="submit" value ="Register book now"></td> </tr> </table></form></body></html>and form for script 2==><html><head> <title> New Name Entry </title></head><body><h1> NAME ENTRY </h1><form action= "insert_name.php" method= "post"> <table border="0"> <tr> <td>First Name</td> <td><input type="text" name 'firstName' maxlength="50" size="10"><br /></td> </tr> <tr> <td>lastName</td> <td><input type="text" name 'lastName' maxlength="50" size="10"><br /></td> </tr> <tr> <td colspan="2"><input type="submit" value ="put names into database"></td> </tr> </table></form></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
pinangsia Posted September 5, 2006 Author Share Posted September 5, 2006 Anyone?its nearly 3 days now,pls don't let me throw in my towel :(( Quote Link to comment Share on other sites More sharing options...
fenway Posted September 5, 2006 Share Posted September 5, 2006 You're not specify the HTML name attribute correctly for your INPUT fields... missing equals sign. Quote Link to comment Share on other sites More sharing options...
pinangsia Posted September 5, 2006 Author Share Posted September 5, 2006 you meant like this one<td><input type="text" name "isbn" maxlength="13" size="13"><br /></td>must be <td><input type="text" name="isbn" maxlength="13" size="13"><br /></td>i couldn't wait to try it... Thanks FenwayAnyone can explain why this one doesn't work? it keeps on saying that i have not entered all values. if (!$isbn || !$author || !$title || !$price){ echo 'You have not entered all required details <br />'.'Please go back and try again.'; exit; Quote Link to comment Share on other sites More sharing options...
fenway Posted September 5, 2006 Share Posted September 5, 2006 I don't think it's wrong... it's syntactically correct. Quote Link to comment Share on other sites More sharing options...
pinangsia Posted September 6, 2006 Author Share Posted September 6, 2006 Its all good now.Thank you Fenway. Quote Link to comment 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.