david_php_nub Posted April 8, 2008 Share Posted April 8, 2008 OK i have a web site where i want people to input they details into a data base. The html page is <HTML> <HEAD> <TITLE>Get in contact</TITLE> </HEAD> <BODY> <br> <br> <br> <img style="position:absolute;top:0;left:0;z-index:-1" src="http://hermes.hud.ac.uk/c0670061/pic1.jpg"> <H1><CENTER><font color="#0000A0" face="Script MT Bold" size="6"> Contact Us </font></CENTER></H1> <br> <br> <br> <br> <H1><CENTER><font color="black" face="Constantia" size="4"> If you are interested in our service please input your details for us to get in touch with you. <br> Alternately you can get in touch with us <a href="http://hermes.hud.ac.uk/c0670061/Companydetails.html">hear</a> </font></CENTER></H1> <br> <form action="Details.php" method=post> <CENTER><table border=0> <tr> <td width=150>First Name</td> <td> <input type="text" name="fname" size="10" maxlength="10"> </td> </tr> <tr> <td width=150>Last Name</td> <td> <input type="text" name="lname" size="10" maxlength="10"> </td> </tr> <tr> <td width=150>Address</td> <td> <textarea name="address" cols="40" rows="5"> </textarea><br> </td> </tr> <tr> <td width=150>Phone Number</td> <td> <input type="text" name="pnumber" size="15" maxlength="15"> </td> </tr> <tr> <td width=150>Email</td> <td> <input type="text" name="email" size="30" maxlength="30"> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value"submit"></td> </tr> </TABLE></CENTER> <CENTER><TABLE BORDER = “1”> <tr> <td> <A HREF = "http://hermes.hud.ac.uk/c0670061/homepage.html">Home</A> </td> <td> <A HREF = "http://hermes.hud.ac.uk/c0670061/Admin.html">Admin</A> </td> <td> <A HREF = "http://hermes.hud.ac.uk/c0670061/Companydetails.html">Company Details</A> </td> </tr> </TABLE></CENTER> </BODY> </HTML> And the details.PHP page is <?php $firstName = $_REQUEST['fname']; $lastName = $_REQUEST['lname']; $address = $_REQUEST['address']; $phoneNumber = $_REQUEST['pnumber']; $email = $_REQUEST['email']; $db = mysql_connect("localhost", "*****", "*****") or die("Could not connect to database"); mysql_select_db("******"); $result = mysql_query("INSERT INTO Client Details (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')"); mysql_close($db); if($result === false) { print_r(mysql_error()); echo "no add"; } else { echo "Good it bloody added"; } ?> details of the database in myphp Table: Client Details Field Type Collation Attributes Null Default Extra Action First_Name varchar(15) latin1_swedish_ci Yes NULL Last_Name varchar(15) latin1_swedish_ci Yes NULL Address text latin1_swedish_ci Yes NULL Phone_Number int(15) Yes NULL Email varchar(30) latin1_swedish_ci No Check All / Uncheck All With selected: The problem is the data is not being saved and the page comes back with "no add" I hope someone can help thanks. Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/ Share on other sites More sharing options...
Barand Posted April 8, 2008 Share Posted April 8, 2008 and the error reported by mysql_error() is what? Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-511867 Share on other sites More sharing options...
zenag Posted April 8, 2008 Share Posted April 8, 2008 alter mysql query... tablename should not space... Client Details change it as ClientDetails $result = mysql_query("INSERT INTO ClientDetails (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')"); Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-511892 Share on other sites More sharing options...
zenag Posted April 8, 2008 Share Posted April 8, 2008 or ur tablename should be... $result = mysql_query("INSERT INTO Client_Details (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')"); Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-511897 Share on other sites More sharing options...
Barand Posted April 8, 2008 Share Posted April 8, 2008 You can use INSERT INTO `Client Details` ... but better not to have spaces in names Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-511903 Share on other sites More sharing options...
david_php_nub Posted April 8, 2008 Author Share Posted April 8, 2008 ok i have changed the database name to "Client_Details" and changed to $result = mysql_query("INSERT INTO 'Client_Details' (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')"); and also trayed $result = mysql_query("INSERT INTO Client_Details (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')"); both show the echo "no add" when i try to input some data, but there are no SQL errors showing up in the myphpadmin. Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-511915 Share on other sites More sharing options...
zenag Posted April 8, 2008 Share Posted April 8, 2008 DO THIS.... $result = mysql_query("INSERT INTO Client_Details (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')"); if(!$result ) { //print_r(mysql_error()); echo "no add"; } else { echo "Good it bloody added"; } Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-511928 Share on other sites More sharing options...
david_php_nub Posted April 8, 2008 Author Share Posted April 8, 2008 Still dont work, thanks anyway Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-511938 Share on other sites More sharing options...
Barand Posted April 8, 2008 Share Posted April 8, 2008 You still have not told us what mysql_error() reported. Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-511972 Share on other sites More sharing options...
david_php_nub Posted April 10, 2008 Author Share Posted April 10, 2008 You still have not told us what mysql_error() reported. how do i find this out? Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-513705 Share on other sites More sharing options...
david_php_nub Posted April 10, 2008 Author Share Posted April 10, 2008 oh there is no error being reported, if(!$result ) { //print_r(mysql_error()); echo "no add"; } the result is coming back as false so the page show "no add" but theres not error being printed. Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-513758 Share on other sites More sharing options...
Barand Posted April 10, 2008 Share Posted April 10, 2008 Speechless! Link to comment https://forums.phpfreaks.com/topic/100111-need-help-inputing-data-into-a-database-useing-phpsql/#findComment-514138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.