Jump to content

Help! Php/MySQL Question!


curbsy

Recommended Posts

index.php

<?php$username = 'curbsy';$password = 'Removed';$hostname = 'localhost';$dbh = mysql_connect($hostname, $username, $password) or die('Unable to connect to MySQL');print 'Connected to MySQL<br><br>';$selected = mysql_select_db('curbsy',$dbh) or die('Could not select to selected database');$result = mysql_query( "SELECT * FROM people" )or die("SELECT Error: ".mysql_error());$num_rows = mysql_num_rows($result);print "There are $num_rows records.<P>";print "<table width=200 border=1>\n<tr><td><font face=arial size=1/>Edit Number:</font></td><td><font face=arial size=1/>First Name:</font></td><td><font face=arial size=1/>Last Name:</font></td><td><font face=arial size=1/>Age:</font></td></tr>";while ($get_info = mysql_fetch_row($result)){ print "<tr>\n";foreach ($get_info as $field) print "\t<td><font face=arial size=1/>$field</font></td>\n";print "</tr>\n";}print "</table>\n";mysql_close();?><html><head><title>People Database</title></head><body><br /><br />Edit The Database<form action='action.php' method='post'>Edit Number: <input type='text' name='num' /><br />First Name: <input type='text' name='fname' /><br />Last Name: <input type='text' name='lname' /><br />Age: <input type='text' name='age' /><br />Password <input type='password' name='pword' /><br /><input type='submit' value='Submit' /></form></body></html>
action.php
<?php// Variables$num = $_POST['num'];$fname = $_POST['fname'];$lname = $_POST['lname'];$age = $_POST['age'];$username = 'curbsy';$pass = $_POST['pword'];$hostname = 'localhost';$dbh = mysql_connect($hostname, $username, $pass) or die('Unable to connect to MySQL');print 'Connected to MySQL<br><br>';$selected = mysql_select_db('curbsy',$dbh) or die('Could not select to selected database');// Add Person To Database$result = mysql_query("UPDATE people SET fname = '$fname', lname = '$lname', age = '$age' WHERE num = '$num'");mysql_close();echo "<a href='http://www.rl6.org/~curbsy/db/index.php'>Back To Database</a>";?>
Can anybody tell me why this doesn't update properly?
Link to comment
Share on other sites

Guest badilcan
index.phpaction.phpCan anybody tell me why this doesn't update properly?

Hi there,firstyou must concantinate stringfor example$name="onur ";$lastname="vargün";$me=$name.$lastname;echo $me//print onur vargünI think you didnt concantinate sql update string ,second,What is mysql column type of age and num,if these are inttry this,$result = mysql_query("UPDATE people SET fname = '".$fname."', lname = '".$lname."'', age =".$age." WHERE num = ".$num."");else these are varchartry this$result = mysql_query("UPDATE people SET fname = '".$fname."', lname = '".$lname."', age ='".$age."' WHERE num = '".$num."'");
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...