I am not having any luck getting this to work. As far as I can tell I want to create a CRUD system. I have a table with 6 fields, I need a way to
a. List all the records
b. Provide a way to Insert a new record
C. Edit an existing record.
Here is what I have so far. I know it is messy.
So I get the list and so far I can click on the button but nothing happens. Once I get that working I need to move onto editing. Eventually all this will lead to creating a xml file IF I am still sane enough to finish it! )
a. List all the records
b. Provide a way to Insert a new record
C. Edit an existing record.
Here is what I have so far. I know it is messy.
Code:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="cqadmin"; // Database name
$tbl_name="phonebooks"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name order by phonebookname";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong></strong></td>
<td align="center"><strong>Phonebook</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Office</strong></td>
<td align="center"><strong>Cell</strong></td>
<td align="center"><strong>Other</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center">
<? $id[]=$rows['id']; ?><?php echo $rows['id']; ?>
</td>
<td align="center">
<input name="phonebookname[]" type="text" id="phonebookname" value="<?php echo $rows['phonebookname']; ?>">
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<?php echo $rows['name']; ?>">
</td>
<td align="center">
<input name="office[]" type="text" id="office" value="<?php echo $rows['office']; ?>">
</td>
<td align="center">
<input name="cell[]" type="text" id="cell" value="<?php echo $rows['cell']; ?>">
</td>
<td align="center">
<input name="other[]" type="text" id="other" value="<?php echo $rows['other']; ?>">
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Add" value="Add"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Add" is active, do this
if($Submit){
$sql="INSERT INTO phonebooks
(id,phonebookname,name,office,cell,other)
VALUES
(?,?,?,?,?,?)";
$result1=mysql_query($sql);
}
if($result1){
header("location:test.php");
}
mysql_close();
?>
</table>
So I get the list and so far I can click on the button but nothing happens. Once I get that working I need to move onto editing. Eventually all this will lead to creating a xml file IF I am still sane enough to finish it! )