truck7758 Posted February 21, 2008 Share Posted February 21, 2008 Hi all, Can anyone see why this form wont insert the data into my sql database? When i click submit i get a blank page and the data doesn't submit. <?php if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form ?> <BODY TEXT="red" LINK="yellow" BGCOLOR="black"> <p> <a href="http://www.ticketline.co.uk"> <img src="new_logo2.jpg" alt="Ticketline_logo" align="center" width="210" height="95" /> </a> Date: <? print strftime("%d/%m/%Y"); ?> </p> <h1 align="center">Create New Supplier</h1> <p align="center"> <form method="post" action="<?php echo $PHP_SELF;?>"> <table> <tr> <td align="center">Name:</td> <td align="center">Tel No:</td> <td align="center">Fax:</td> <td align="center">Website:</td> <td align="center">E-Mail:</td> </tr> <tr> <td align="center"><input type='text' name='name' value='' size='25'></td> <td align="center"><input type='text' name='telno' value='' size='15'></td> <td align="center"><input type='text' name='fax' value='' size='15'></td> <td align="center"><input type='text' name='website' value='' size='15'></td> <td align="center"><input type='text' name='email' value='' size='15'></td> </tr> <tr> <td align="center">Account No:</td> <td align="center">Account Manager:</td> <td align="center">Account Login:</td> <td align="center">Account Password:</td> </tr> <tr> <td align="center"><input type='text' name='accnumber' value='' size='15'></td> <td align="center"><input type='text' name='accmanager' value='' size='15'></td> <td align="center"><input type='text' name='acclogin' value='' size='15'></td> <td align="center"><input type='text' name='accpassword' value='' size='15'></td> </tr> <tr> <td align="center">Address:</td> <td align="center">Other Info:</td> </tr> <tr align="center"> <td><textarea rows="5" cols="20" name="address" wrap="physical"></textarea><br /></td> <td><textarea rows="5" cols="20" name="other" wrap="physical"></textarea><br /></td> </tr> </table> <input type="submit" value="Submit" name="submit" STYLE="font-family:sans-serif; font-size:large; font-style:italic; background:red; color:black; width:6em; height:1.5em"> </form> <? } else { $host = "localhost"; $username = "username"; $password = "password"; $database = "orders"; $mysqli = mysqli_connect('localhost','uname','password'); $mysqli->select_db('supplier'); $name = $_POST["name"]; $telno = $_POST["telno"]; $fax = $_POST["fax"]; $website = $_POST["website"]; $email = $_POST["email"]; $accnumber = $_POST["accnumber"]; $accmanager = $_POST["accmanager"]; $acclogin = $_POST["acclogin"]; $accpassword = $_POST["accpassword"]; $address = $_POST["address"]; $other = $_POST["other"]; $name = addslashes($name); $telno= addslashes($telno); $fax = addslashes($fax); $website= addslashes($website); $email= addslashes($email); $accnumber= addslashes($accnumber); $accmanager = addslashes($accmanager); $acclogin = addslashes($acclogin); $accpassword = addslashes($accpassword); $address = addslashes($address); $other = addslashes($other); if(!$mysqli) { echo " Error: could not connect to database."; exit; } $sql="INSERT INTO `supplier` (`name`, `address`, `telno`, `fax`, `website`, `accountno`, `accountmanager`, `email`, `accountlogin`, `accountpwd`, `otherinfo`) VALUES ('".$name."', '".$address."', '".$telno."', '".$fax."', '".$website."', '".$accnumber."', '".$accmanager."', '".$email."', '".$acclogin."', '".$accpassword."', '".$other."')"; $result = mysqli_query($mysqli, $sql, MYSQLI_USE_RESULT); if($result) { echo mysqli_affected_rows($mysqli)." .Supplier Table Updated."; } } ?> Cheers, Mike Quote Link to comment Share on other sites More sharing options...
themistral Posted February 21, 2008 Share Posted February 21, 2008 Try echoing or printing out the query and then try running it in the database - you may have typed a wrong fieldname or something. Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Author Share Posted February 21, 2008 Hi, I have just done this in mysql and it inserted into the table: INSERT INTO `supplier` (`name`, `address`, `telno`, `fax`, `website`, `accountno`, `accountmanager`, `email`, `accountlogin`, `accountpwd`, `otherinfo`) values ("test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test"); i also echo'd $sql and i get the following: INSERT INTO `supplier` (`name`, `address`, `telno`, `fax`, `website`, `accountno`, `accountmanager`, `email`, `accountlogin`, `accountpwd`, `otherinfo`) VALUES ('mike', '25 dkfhj,kf wffjkk fefe fedfgggdf m1 1jg', '12345678', '87654321', 'www.test.co.uk', '7758', 'me', 'michael@test.co.uk', 'test', '1234', 'asefjsd sdfgvsdfgdfg sdfgsdf') This seems correct to me. Thanks, Mike Quote Link to comment Share on other sites More sharing options...
aschk Posted February 21, 2008 Share Posted February 21, 2008 Your script is setting the $user/$pass variables etc, but never actually uses them. See your following snippet of code: $username = "username"; $password = "password"; $database = "orders"; $mysqli = mysqli_connect('localhost','uname','password'); Therefore I expect that you're not actually connecting to the database in the first place. I would verify this as it seems inconsistent. Also, you might consider using mysqli_error() to see what your error is (i.e. why it's not working...) Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Author Share Posted February 21, 2008 Hi aschk, how do i go about using mysqli_error? Thanks, Mike Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Author Share Posted February 21, 2008 ok, underneath: if($result) i inserted the following: printf("Errormessage: %s\n", mysqli_error($result)); Now when i click submit it says: 4294967295 .Supplier Table Updated. Any ideas? Cheers, Mike Quote Link to comment Share on other sites More sharing options...
aschk Posted February 21, 2008 Share Posted February 21, 2008 Specify the connection to mysqli_error e.g. echo mysqli_error($mysqli); What does MYSQLI_USE_RESULT do? Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Author Share Posted February 21, 2008 i have just tried adding echo mysqli_error($mysqli); underneath if($result). I get the same message as before. im not sure what MYSQLI_USE_RESULT does but i just took it out and it makes no difference. Cheers, Mike Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Author Share Posted February 21, 2008 Any ideas??? thanks 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.