Jump to content

spanner206

Members
  • Posts

    82
  • Joined

  • Last visited

Everything posted by spanner206

  1. hi ive been trying to sort this out all day, im very inexperianced in php but really want to do well in it and at the moment ive got a table working linked to a database and which pulls records but now i want to get an update and delete button but i cant seem to hack it heres the code. <?php $con = mysqli_connect("localhost","root","","lcm"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //updates table. if (isset($_POST['update'])){; $UpdateQuery = "UPDATE tbl_contactinfo SET Name='$_POST[Name]', Address='$_POST[Address]' WHERE Name='$_POST[hidden]'"; mysql_query($UpdateQuery, $con); } if (isset($_POST['delete'])){; $DeleteQuery = "DELETE FROM tbl_contactinfo WHERE Name='$_POST[hidden]'"; mysql_query($DeleteQuery, $con); } //selects the table. $sql = "Select * from tbl_contactinfo"; if ($result = mysqli_query($con, $sql)) { echo "<table border='1'> <tr> <th>Name</th> <th>Address</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo '<form action="index1.php" method="post">'; echo '<tr>'; echo '<td><input type="text" name="name" value="' . $row['Name'] . '" /></td>'; echo '<td><input type="text" name="address" value="' . $row['Address'] . '" /></td>'; echo '<td><input type="hidden" name="hidden" value="' . $row['ID'] . '" /></td>'; echo '<td><input type="submit" name="update" value="update" /></td>'; echo '<td><input type="submit" name="delete" value="delete" /></td>'; echo '</tr>'; echo '</form>'; } echo "</table>"; } ?> <html> <body> <form action="insert.php" method="post"> Name: <input type="text" name="Name"> Address: <input type="text" name="Address"> <input type="submit"> </form> </body> </html> and error messages ive been getting. ( ! ) Notice: Undefined index: Name in C:\wamp\www\Index1.php on line 12 Call Stack # Time Memory Function Location 1 0.0000 147208 {main}( ) ..\Index1.php:0 ( ! ) Notice: Undefined index: Address in C:\wamp\www\Index1.php on line 12 Call Stack # Time Memory Function Location 1 0.0000 147208 {main}( ) ..\Index1.php:0 ( ! ) Warning: mysql_query() expects parameter 2 to be resource, object given in C:\wamp\www\Index1.php on line 13 Call Stack # Time Memory Function Location 1 0.0000 147208 {main}( ) ..\Index1.php:0 2 0.1562 154608 mysql_query ( ) ..\Index1.php:13 these are for update and for delete ( ! ) Warning: mysql_query() expects parameter 2 to be resource, object given in C:\wamp\www\Index1.php on line 18 Call Stack # Time Memory Function Location 1 0.0000 147208 {main}( ) ..\Index1.php:0 2 0.1406 154456 mysql_query ( ) ..\Index1.php:18 ive stoped the error messages before dont no how i did it but they wernt showing, only problem is when i pressed them nothing happened any help will be great.
  2. yh sorry about that i was playing around trying to figure it out but now ive changed it back im getting no error messages but the update button is more like a reset because when i press it it resets the changes i make to the records, any ideas??
  3. actually scratch that when i press update these messages comes up. ( ! ) Notice: Undefined index: Name in C:\wamp\www\Index1.php on line 12 Call Stack # Time Memory Function Location 1 0.0000 146432 {main}( ) ..\Index1.php:0 ( ! ) Notice: Undefined index: Address in C:\wamp\www\Index1.php on line 13 Call Stack # Time Memory Function Location 1 0.0000 146432 {main}( ) ..\Index1.php:0
  4. YES, GET IN, CHEERS FOR EVERYONES HELP :D :D :D :D
  5. HI again ive pasted the new code in and now im starting to get another error (as you can probably tell i barely no anything ) ( ! ) Parse error: syntax error, unexpected 'Name' (T_STRING), expecting ',' or ';' in C:\wamp\www\Index1.php on line 33
  6. this is the error ( ! ) Parse error: syntax error, unexpected end of file in C:\wamp\www\Index1.php on line 39
  7. hi ive been trying to sort this update button out but i keep getting errors and got no clue how to fix it. heres the code. <?php $con=mysqli_connect("localhost","","","lcm"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = "Select * from tbl_contactinfo"; if (isset($_POST['update'])){ $UpdateQuery = "UPDATE tbl_contactinfo SET Name='$_POST[Name]', Address='$_POST[Address]' WHERE Name = '$_post[hidden]'"; mysql_query($UpdateQuery,$con); }; if ($result = mysqli_query($con, $sql)){ echo "<table border='1'> <tr> <th>Name</th> <th>Address</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<form action = index1.php method =post>"; echo "<tr>"; echo "<td>" . "<input type= text name =Name value =" . $record['Name'] . "</td>"; echo "<td>" . "<input type= text name =address value =" . $record['Address'] . "</td>"; echo "<td>" . "<input type= hidden hidden =Name value =" . $record['hidden'] . "</td>"; echo "<td>" . "<input type= submit name = update value=update". " </td>"; echo "</form>"; } echo "</table>"; mysql_close($con); ?> if someone could help id really apreciate it.
×
×
  • 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.