barryflood22 Posted April 10, 2007 Share Posted April 10, 2007 Hi, iv managed to get my database to add a new record and create a new unique ID. but its not copying accross the customer information correctly for some reason. its creating the new record in the table, inserting a new unique id but leaving the name and address fields blank, any help? FROM WHAT I CAN GATHER - ITS NOT STORING THE INFORMATION INT EH TEXT FIELD TO BRING IT ACCROSS TO THE SECOND PAGE, PLEASE ADVISE CUSTOMER-INSERT.PHP <a href="index.php">< back</a><br /> <?php // This file contains the database access information. This file also establishes a connection to MySQL and selects the database. // Set the database access information as constants. $DBhost = "localhost"; $DBuser = "root"; $DBpass = ""; $DBName = "bf-customer"; $table = "customer"; mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); ?> <!-- <?php //This file do the actual insert in the database after the connection is established. $query="SELECT * FROM customer"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Customer Name: </b>"; echo "<select name='name' size='1'>"; $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); /* echo "<b>$name</b><br>"; */ echo "<option value=\"$id\">$name</option>"; $i++; } echo "</select>"; echo "</center>"; echo "<br />"; ?> --> <center> <u>Insert New Customer</u> <form method="post" action="customer-insert-process.php"> <input type="hidden" name="id" value="null"> <table> <tr> <td align="left">Customer Name: </td> <td><input type="text" name="name" size="20"></td> <tr> <tr> <td align="left">Customer Address: </td> <td><input type="text" name="address" size="20"></td> </tr> <input type="submit" value="Enter record"> </table> </form> </center> CUSTOMER-INSERT-PROCESS.PHP <a href="index.php">< back</a><br /> <?php // Set the database access information as constants. $DBhost = "localhost"; $DBuser = "root"; $DBpass = ""; $DBName = "bf-customer"; $table = "customer"; mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); // the 'insert' that will insert the data as a new row into the table under the respective columns. mysql_query("INSERT INTO customer (name, address) VALUES('$name', '$address' ) ") or die(mysql_error()); echo "<br />"; echo "$name inserted"; ?> Link to comment https://forums.phpfreaks.com/topic/46450-solved-adding-new-records-to-database/ Share on other sites More sharing options...
MadTechie Posted April 10, 2007 Share Posted April 10, 2007 change CUSTOMER-INSERT-PROCESS.PHP from <?php mysql_query("INSERT INTO customer (name, address) VALUES('$name', '$address' ) ") or die(mysql_error()); ?> to <?php mysql_query("INSERT INTO customer (name, address) VALUES('{$_POST['name']}', '{$_POST['address']}' ) ") or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/46450-solved-adding-new-records-to-database/#findComment-225955 Share on other sites More sharing options...
trq Posted April 10, 2007 Share Posted April 10, 2007 mysql_query("INSERT INTO customer (name, address) VALUES ('". mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['address']) . "')"); Link to comment https://forums.phpfreaks.com/topic/46450-solved-adding-new-records-to-database/#findComment-225956 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 still got the same problem... Link to comment https://forums.phpfreaks.com/topic/46450-solved-adding-new-records-to-database/#findComment-225957 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 FIXED :-D thanks! Link to comment https://forums.phpfreaks.com/topic/46450-solved-adding-new-records-to-database/#findComment-225959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.