Jump to content

[SOLVED] adding new records to database


barryflood22

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.