Poddy Posted February 15, 2008 Share Posted February 15, 2008 hi, i'm trying to build a form which you answer questions and it stores them on a mysql database while the user is identified by an integer value in user_id field in the table.. however when i try to UPDATE the row it just gives me the 500 internal error message which i know is a fatal error in my php script.. when i remove the update command it works perfectly... it's just dosent add it to the the database which i need it to.. when i comment this row everything works fine, but nothing gives the order to put it into the database $query = "UPDATE users WHERE user_id='12345' SET q1='$q1', q2='$q2', q3='$q3', q4='$q4' " mysql_query($query) or die('Error, update query failed') <html> <body> <?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $dbname = 'users'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname) or die ('Error selecting database'); print_r($_POST);## Uncomment this to have the POST variables printed if(isset($_POST['submit'])){ $q1 = mysql_real_escape_string($_POST['q1']); $q2 = mysql_real_escape_string($_POST['q2']); $q3 = mysql_real_escape_string($_POST['q3']); $q4 = mysql_real_escape_string($_POST['q4']); $query = "UPDATE users WHERE user_id='12345' SET q1='$q1', q2='$q2', q3='$q3', q4='$q4' " mysql_query($query) or die('Error, update query failed') } ?> <div align="center"><h1>Title</h1></div> <p align="center">please answer these questions</p> <form action="<?php echo $PHP_SELF?>" method="post" name="questions"> <?php $query = "SELECT * FROM questions WHERE q_id='1'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row['q_txt']; ?> <input name="q1" type="text"><br> <label> <?php $query = "SELECT * FROM `questions` WHERE q_id='2'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row['q_txt']; ?> </label> <input name="q2" type="text"><br> <label> <?php $query = "SELECT * FROM `questions` WHERE q_id='3'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row['q_txt']; ?> </label> <input name="q3" type="text"><br> <label> <?php $query = "SELECT * FROM `questions` WHERE q_id='4'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row['q_txt']; ?> </label> <input name="q4" type="text"><br> <br> <input name="submit" value="Submit" type="submit"> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/91236-php-script-generates-fatal-error-on-mysql-update-command/ Share on other sites More sharing options...
redarrow Posted February 15, 2008 Share Posted February 15, 2008 <?php if(isset($_POST['submit'])){ $q1 = mysql_real_escape_string($_POST['q1']); $q2 = mysql_real_escape_string($_POST['q2']); $q3 = mysql_real_escape_string($_POST['q3']); $q4 = mysql_real_escape_string($_POST['q4']); $query ="UPDATE users SET q1='$q1', q2='$q2', q3='$q3', q4='$q4' where user_id='12345' "; $result="mysql_query($query) or die('Error, update query failed')"; } ?> Link to comment https://forums.phpfreaks.com/topic/91236-php-script-generates-fatal-error-on-mysql-update-command/#findComment-467603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.