The script is supposed to receive data from a HTML form and update the table based on the supplied information. This is what I get:

"Connected successfully
Selected successfully
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in on line 39
Query was empty"

<? 
 $name =  $_POST["name"]; 
 $show = $_POST["show"]; 
 $first = $_POST["first"]; 
 $second = $_POST["second"]; 
 $third = $_POST["third"]; 
 $fourth = $_POST["fourth"]; 
 $fifth = $_POST["fifth"];
 $sixth = $_POST["sixth"]; 
 
 $first = $first* 6;
 $second = $second * 5;
 $third = $third * 4;
 $fourth = $fourth * 3;
 $fifth = $fifth * 2;
 $sixth = $sixth * 1;
 $total = $first + $second + $third + $fourth + $fifth + $sixth;

$dbhost = "dbhost";
$dbuser = "dbuser";
$dbpass = "dbpass";
$dbname = "dbname";

$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass");
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';

$select = mysql_select_db("$dbname");
if (!$select) {
    die('Could not connect: ' . mysql_error());
}
echo 'Selected successfully';

$query = mysql_query("UPDATE nomsire SET show = $total WHERE name = '$name'",
mysql_real_escape_string($name,$conn));

mysql_query ($query,$conn) or die (mysql_error()); 

mysql_close($conn);

?>

Replace lines 36 through 39 with:

$name = mysql_real_escape_string($name, $conn);
$query = "UPDATE nomsire SET show = $total WHERE name = '$name'";
mysql_query($query, $conn) or die(mysql_error());

I get, if I submit the form:
Connected successfully
Selected successfullyYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show = 68 WHERE name = 'Arctic'' at line 1

Are you trying to update the name Arctic' (note the single quote), or is it a typo ?

It must be a typo, since I entered the name as Arctic, without any quotes. Or is it getting stuck on the text within quotes, even with the mysql_real_escape_string?

Here's the form, if that helps any.

<form enctype="multipart/form-data" action="edit.php" method="POST">

Stallion to Edit: <input type="text" name="name"><br />
Show Name: <input type="text" name="show"><br />
1st Places: <input type="text" name="first"><br />
2nd Places: <input type="text" name="second"><br />
3rd Places: <input type="text" name="third"><br />
4th Places: <input type="text" name="fourth"><br />
5th Places: <input type="text" name="fifth"><br />
6th Places: <input type="text" name="sixth"><br />

<input type="submit" name="edit" value="edit"></form>

it's very useful us.Thank You so much

there is sticky at the top for this common issue. Please take time to read it and understand what is cause and what others have faced

Member Avatar for rajarajan2017

Use the else statement like below otherwise even if its not connected, it shows connected:

$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass");
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
else echo 'Connected successfully<br />';

$select = mysql_select_db("$dbname");
if (!$select) {
    die('Could not connect: ' . mysql_error());
}else echo 'Selected successfully';

Thank you to everyone!

I got it working after I added backticks around "nomsire", "show", and "name" and then it also worked when I removed the backticks but replaced the field name "show" with another word, since it's a reserved word.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.