intodesi Posted March 30, 2008 Share Posted March 30, 2008 Ok, new here and new to php and mysql so been web browsing to figure out a database i would like to create. The database is to keep track of my pc's, their mac id etc. from google i have come up with the following, bear with me; I have 5 pages thus far, I know security on them is weak, but they are for local server only, i know to add the mysql connect info to another page, but this is a work in process the ones i am having difficulty with are edit_form.php and edit_data.php edit_form.php as follows; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">; <html> <head> <title>Form Edit Data</title> </head> <body> <table border=1> <tr> <td align=center>Edit Computer Data</td> </tr> <tr> <td> <table> <? $database="computer"; mysql_connect ("localhost", "michael", "michaelpass"); @mysql_select_db($database) or die( "Unable to select database"); $id=$_GET['id']; $order = "SELECT * FROM information WHERE id='$id'"; $result = mysql_query($order); $row = mysql_fetch_array($result); ?> <form method="post" action="edit_data.php"> <input type="hidden" name="id" value="<? echo $row['id'];?>"> <tr> <td>Name</td> <td> <input type="text" name="name" size="20" value="<? echo $row['name'];?>"> </td> </tr> <tr> <td>Workgroup</td> <td> <input type="text" name="workgroup" size="40" value="<? echo $row['workgroup'];?>"> </td> </tr> <tr> <td>IP Address</td> <td> <input type="text" name="ip" size="40" value="<? echo $row['ip'];?>"> </td> </tr> <tr> <td>MAC Address</td> <td> <input type="text" name="mac" size="40" value="<? echo $row['mac'];?>"> </td> </tr> <tr> <td>Location</td> <td> <input type="text" name="location" size="40" value="<? echo $row['location'];?>"> </td> </tr> <tr> <td>Use</td> <td> <input type="text" name="use" size="40" value="<? echo $row['use'];?>"> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit value" value="Edit"> </td> </tr> </form> </table> </td> </tr> </table> </body> </html> edit_data.php.. with this I was using the e.g. &database="computer"; as a test to see if the edit form data was carrying over as you can see in my else statement which would echo $name.. which would write what $name is. but this always gives me my error statement, and it does return the updated information regarding that row in the specific table represented by id.. but like i said it give me my error, and doesn't update the database... I hope thats clear, but will answer questions regarding my questions regarding all of this <? $database="computer"; $id=$_POST['id']; $name=$_POST['name']; $workgroup=$_POST['workgroup']; $ip=$_POST['ip']; $mac=$_POST['mac']; $location=$_POST['location']; $use=$_POST['use']; mysql_connect ("localhost", "michael", "michaelpass"); @mysql_select_db($database) or die( "Unable to select database"); $order = "UPDATE information SET name='$name', workgroup='$workgroup', ip='$ip', mac='$mac', location='$location', use='$use' WHERE id='$id'"; $result=mysql_query($order); if($result){ echo "Successful"; echo "<BR>"; echo "<a href='information.php'>Back to Records</a>"; } else { echo "ERROR"; echo $name; } ?> Any and all help is apreciated, this is a personal project, and would like to see it work Link to comment https://forums.phpfreaks.com/topic/98577-php-update-and-set-syntax/ Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 your need to use the built in php server functions http://uk2.php.net/reserved.variables but remember dont rely on built in functions ok m8. Link to comment https://forums.phpfreaks.com/topic/98577-php-update-and-set-syntax/#findComment-504541 Share on other sites More sharing options...
wolfcry Posted March 30, 2008 Share Posted March 30, 2008 have you tried the following? if($result == 1){ echo "Successful"; echo "<BR>"; echo "<a href='information.php'>Back to Records</a>"; } else { echo "ERROR"; echo $name; } ?> Link to comment https://forums.phpfreaks.com/topic/98577-php-update-and-set-syntax/#findComment-504685 Share on other sites More sharing options...
intodesi Posted March 31, 2008 Author Share Posted March 31, 2008 Still Getting error even with new coding wolfcry suggested if($result == 1){ echo "Successful"; echo "<BR>"; echo "<a href='information.php'>Back to Records</a>"; } else { echo "ERROR"; echo "<br>"; echo $name; } as far as using the built in server functions, i tried reading through that and I am lost.. but still trying to see what you want me to see.. Link to comment https://forums.phpfreaks.com/topic/98577-php-update-and-set-syntax/#findComment-505359 Share on other sites More sharing options...
intodesi Posted March 31, 2008 Author Share Posted March 31, 2008 OK after changing my coding arround i am getting this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'use= 'gggg' WHERE id= '1'' at line 1 new code <? $database="computer"; $id=$_GET['id']; $ud_name=$_POST['name']; $ud_workgroup=$_POST['workgroup']; $ud_ip=$_POST['ip']; $ud_mac=$_POST['mac']; $ud_location=$_POST['location']; $ud_use=$_POST['use']; mysql_connect ("localhost", "michael", "michaelpass"); @mysql_select_db($database) or die( "Unable to select database"); mysql_query("UPDATE information SET name='$ud_name', workgroup= '$ud_workgroup', ip= '$ud_ip', mac= '$ud_mac', location= '$ud_location', use= '$ud_use' WHERE id= '$id' ") or die(mysql_error()); ?> Do i have a syntax error in my mysql_query? Link to comment https://forums.phpfreaks.com/topic/98577-php-update-and-set-syntax/#findComment-505426 Share on other sites More sharing options...
intodesi Posted April 1, 2008 Author Share Posted April 1, 2008 OK Figured it out.. php is strange to the begginer.. on the mysql forums it was suggested i use ` for my `use` database row.. well i entered that is 'use' seems ` and ' are two different (dont know what to call them) characters in php.. I hardly ever use the ` guess i will know now.. anyways.. my script now works... I can successfully update my databases Link to comment https://forums.phpfreaks.com/topic/98577-php-update-and-set-syntax/#findComment-506225 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.