AEdwards Posted April 23, 2012 Share Posted April 23, 2012 <?php include 'header.php'; ?> <form name="form1" method="post" action="insert_ac.php"> <table id="formcss" width="100%" border="0" cellspacing="1" cellpadding="3" align="center"> <tr> <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td> </tr> <tr> <td width="71">Name</td> <td width="6">:</td> <td width="301"><input name="name" type="text" id="name"></td> </tr> <tr> <td>Company</td> <td>:</td> <td><input name="company" type="text" id="company"></td> </tr> <tr> <td>Phone</td> <td>:</td> <td><input name="phone" type="text" id="phone"></td> </tr> <tr> <td>Mobile</td> <td>:</td> <td><input name="mobile" type="text" id="mobile"></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td>Called</td> <td>:</td> <td><input type="checkbox" name="call" value="training" /> Training <input type="checkbox" name="call" value="business" /> Business <input type="checkbox" name="call" value="legal" /> Legal <input type="checkbox" name="call" value="other" /> Other</td> </tr> </tr> <tr> <td>Patched To</td> <td>:</td> <td> <select name="patch"> <option value="sperkins">S.Perkins</option> <option value="srayson">S.Rayson</option> <option value="strandafil">S.Trandafil</option> <option value="tmoore">T.Moore</option> <option value="lharding">L.Harding</option> <option value="vmitchell">V.Mitchell</option> <option value="achilvers">A.Chilvers</option> <option value="aedwards">A.Edwards</option> <option value="rfrost">R.Frost</option> <option value="ohoogenhout">O.Hoogenhout</option> <option value="pkeily">P.Keily</option> </select> </td> </tr> <tr> <td>Filled out by</td> <td>:</td> <td><input name="user" type="text" id="user"></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> <?php include 'footer.php'; ?> <?php $host="Localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['name']; $company=$_POST['company']; $phone=$_POST['phone']; $mobile=$_POST['mobile']; $email=$_POST['email']; $call=$_POST['call']; $patch=$_POST['patch']; $user=$_POST['user']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, company, phone, mobile, email, call, patch, user)VALUES('$name', '$company', '$phone' '$mobile', '$email', '$call', '$patch', '$user')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='insert.php'>Back to main page</a>"; } else { echo "ERROR 1"; //This is where the error is. Not sure why it's not working } // close connection mysql_close(); ?> Can anyone see what i've done wrong here? I swear my brain is going to explode if i look over this one more time. Just a simple form trying to submit to the database :-\ Quote Link to comment https://forums.phpfreaks.com/topic/261456-error-message/ Share on other sites More sharing options...
ManiacDan Posted April 23, 2012 Share Posted April 23, 2012 You should always actually echo mysql_error() to read the error message. Your problem is that at least one (maybe two) of your column names on that table are reserves mysql keywords. Enclose column names in `backticks` to avoid this error. Probably, I mean, I don't have your database or anything other than a single comment saying a single query has failed. Quote Link to comment https://forums.phpfreaks.com/topic/261456-error-message/#findComment-1339750 Share on other sites More sharing options...
AEdwards Posted April 23, 2012 Author Share Posted April 23, 2012 ERROR 1 Query: INSERT INTO members(name, company, phone, mobile, email, call, patch, user)VALUES('Name Test', 'Company Test', 'Phone Test' 'Mobile Test', 'Email Test', 'other', 'aedwards', 'A.Edwards') Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'call, patch, user)VALUES('Name Test', 'Company Test', 'Phone Test' 'Mobile Test'' at line 1 Sorry bout that, I've got it it another post from earlier. Quote Link to comment https://forums.phpfreaks.com/topic/261456-error-message/#findComment-1339754 Share on other sites More sharing options...
AEdwards Posted April 23, 2012 Author Share Posted April 23, 2012 After changing the ' to ` I've got: ERROR 1 Query: INSERT INTO members(`name`, `company`, `phone`, `mobile`, `email`, `call`, `patch`, `user`)VALUES('', '', '' '', '', '', '', '') Error: Column count doesn't match value count at row 1 Quote Link to comment https://forums.phpfreaks.com/topic/261456-error-message/#findComment-1339757 Share on other sites More sharing options...
AEdwards Posted April 23, 2012 Author Share Posted April 23, 2012 I'd missed a , between two values Quote Link to comment https://forums.phpfreaks.com/topic/261456-error-message/#findComment-1339758 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.