Jump to content

Recommended Posts

Hi

I have a problem, when i click on Change name the page refreshes but with a GET value of ?change1.

I then have an isset value which states that if there is a GET value then do something. That something is to change the name of something in my mysql table. The MSQL is setup properly, however when this isset is functioned i get a mysql_error which is:

 

"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 's name to Rhys

 

--------------------------------------------------------------------------------

') WHERE `username` = 'thebusinesstycoon'' at line 1"

 

The code is:

<?php include "banner.php";
if(isset($_GET['change1'])){
$c1 = $_GET['change1'];
$oldname = $logged[factory1];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory1 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change2'])){
$c1 = $_GET['change2'];
$oldname = $logged[factory2];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory2 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change3'])){
$c1 = $_GET['change3'];
$oldname = $logged[factory3];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory3 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change4'])){
$c1 = $_GET['change4'];
$oldname = $logged[factory4];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory4 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change5'])){
$c1 = $_GET['change5'];
$oldname = $logged[factory5];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory5 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change6'])){
$c1 = $_GET['change6'];
$oldname = $logged[factory6];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory6 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change7'])){
$c1 = $_GET['change7'];
$oldname = $logged[factory7];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory7 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change8'])){
$c1 = $_GET['change8'];
$oldname = $logged[factory8];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory8 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change9'])){
$c1 = $_GET['change9'];
$oldname = $logged[factory9];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory9 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}
if(isset($_GET['change10'])){
$c1 = $_GET['change10'];
$oldname = $logged[factory10];
$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname's name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")or die(mysql_error());
$change1 = mysql_query("UPDATE thebusinesstycoon SET factory10 = '$c1' WHERE `username` = '$logged[username]'")or die(mysql_error());
echo "<h1>Changed</h1><font size=\"4\"><font face=\"snap itc\">Click <a href=\"properties.php\">here</a> to return to Properties.";
}





if(isset($_GET['changename1'])){
echo "Factory Name: ".$logged[factory1]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change1\" value=\"$logged[factory1]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename2'])){
echo "Factory Name: ".$logged[factory2]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change2\" value=\"$logged[factory2]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename3'])){
echo "Factory Name: ".$logged[factory3]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change3\" value=\"$logged[factory3]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename4'])){
echo "Factory Name: ".$logged[factory4]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change4\" value=\"$logged[factory4]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename5'])){
echo "Factory Name: ".$logged[factory5]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change5\" value=\"$logged[factory5]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename6'])){
echo "Factory Name: ".$logged[factory6]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change6\" value=\"$logged[factory6]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename7'])){
echo "Factory Name: ".$logged[factory7]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change7\" value=\"$logged[factory7]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename8'])){
echo "Factory Name: ".$logged[factory8]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change8\" value=\"$logged[factory8]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename9'])){
echo "Factory Name: ".$logged[factory9]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change9\" value=\"$logged[factory9]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}
if(isset($_GET['changename10'])){
echo "Factory Name: ".$logged[factory10]."<br /><br /> <form name=\"change\" action=\"properties.php\" method=\"get\"><input type=\"text\" name=\"change10\" value=\"$logged[factory10]\" class=\"input\"><br /><input type=\"submit\" value=\"Change Name\" class=\"input\"></form>";
}



if(isset($_GET['viewfactories'])) {
echo "<font size=\"4\"><font face=\"snap itc\">You Currently have ".$logged[factories]." factories. Click on the factories below to view the staff info and to change the factories name.<br /><br />";
if($logged[factories] == "1"){
echo "-".$logged[factory1];
echo'
<form name="viewfactor" action="properties.php" method="get">
<input type="submit" value="View Staff" name="factoryinfo1" class="input">
</form><form name="changename" action="properties.php" method="get">
<input type="submit" value="Change Name" name="changename1" class="input">
</form><br /><br />
';
}
?>

 

What should i do??

Thanks

Link to comment
https://forums.phpfreaks.com/topic/149380-solved-mysql-help/
Share on other sites

Only showing the first fix, you can do the rest:

 

$updatenews= mysql_query("UPDATE thebusinesstycoon SET news = CONCAT(news, '<br />$date:You have changed $oldname\'s name to $c1<br /><hr />') WHERE `username` = '$logged[username]'")

 

You need to escape single quotes when used inside mysql values, as above $oldname's should be $oldname\'s.

Link to comment
https://forums.phpfreaks.com/topic/149380-solved-mysql-help/#findComment-784556
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.