Jump to content

[SOLVED] Update field help please


lewisstevens1

Recommended Posts

Hello i need some help updating a field in my database, i dont know what i am doing wrong...heres my code.

 

<?php

$con = mysql_connect("localhost","*********","**********");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("**********", $con);

mysql_query("UPDATE available SET sex= 'Male'
WHERE id = '1'");mysql_close($con);
?>

available = table | sex = field

 

I on the front page it says if they are male or female, what i want is it to change when they click a button, it has to be on a seperate page, so i thought just add the Male/Female words in a database and then just recall that, i can recall that, though when i update the field, it does nothing. if i add a field it will show it twice. What can i do?

 

please can someone help

 

Many thanks

Lewis Stevens

Link to comment
Share on other sites

try this code

<?php

$con = mysql_connect("localhost","*********","**********");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("**********", $con);

mysql_query("UPDATE available SET sex= 'Male' WHERE id = '1'",$con) or die(mysql_error($con));
mysql_close($con);

that will exit if there is a error with your query.

and hopefully tell you what is going wrong

 

Scott.

 

Link to comment
Share on other sites

well try this

 

mysql_query("UPDATE available SET sex= 'Male' WHERE id = '1'",$con) or die(mysql_error($con));
echo mysql_affected_rows($con);
mysql_close($con);

are you sure there is a row with an ID of 1 and a sex of Female? other wise you wont see anything

 

Scott.

 

Link to comment
Share on other sites

Well i using sorta same code as the one to get the data to display before the update the next code will make more sense if you read the private message i sent you.

 

$result = mysql_query("SELECT * FROM available WHERE id='1'");
while($row = mysql_fetch_array($result))
  {
echo "<td><font color='green'> ". $row['deathknight'] . "<br></font></td>";
mysql_close($con);

Link to comment
Share on other sites

looking at that and the PM i still can't see any reasons why it wont update.

the only thing i can think of done but have you tired the echo  mysql_affected_rows

also are there any other if's around the update section that could stop the update from happening?

they might need rechecking

also try to add say echo "UPDATING NOW"; on the line after the query to make sure it gets to that line?

 

Scott.

Link to comment
Share on other sites

the only ifs i have are:

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

in the connection variable

 

though between my connection part, and the echo part there is a function i am not sure, if needed. i will signify with wrapping --------- around it.

 

 

mysql_select_db("stonersg_darkfamily", $con);
------------------------------------------------------------------
$result = mysql_query("SELECT * FROM available WHERE id='1'");
------------------------------------------------------------------
echo "Recruitment Table:<br><br>";
?>
<div id="class" div align="left">
<?php
while($row = mysql_fetch_array($result))
  {
echo "<tr><img src='classimg/deathknight_small.gif'> Death Knight:";
  echo "<td><font color='green'> ". $row['deathknight'] . "<br></font></td>";

Link to comment
Share on other sites

woah i accidently echoed it within the wrong document, the one that is ment to have the words change once it echos from the database, though i had nothing change when i echoed here

 

	echo "<tr><img src='classimg/warrior_small.gif'> Warrior:";
   echo "<td><font color='green'> " . $row['warrior'] . "<br></font></td>";
  echo "Updating Now Inside";

   
   
   
  echo "</tr>";

Link to comment
Share on other sites

though i may have forgot the <p> tags there, though i tried in process.php here and i am not getting any sort of output...just a blank screen like usual.

 

<?php
//Deathknight Available-Not Available

$con = mysql_connect("localhost","stonersg_dfadmin","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("stonersg_darkfamily", $con);

mysql_query("UPDATE available SET deathknight='Available' WHERE id = '1'", echo "<p>Hi</p>";$con) or die(mysql_error($con));
mysql_close($con);
echo "<p>Vye</p>";
?>

Link to comment
Share on other sites

The posted code contains a fatal parse error, because you cannot put echo statements inside of other statements. You must follow the syntax that each statement requires.

 

You should be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini (stop and start your web server to get any change made to php.ini to take effect.) By doing this, your blank page will instead show the fatal parse error that is preventing it from executing.

Link to comment
Share on other sites

What does a phpinfo() statement show for the error_reporting and display_errors settings?

 

Error_reporting should be E_ALL. Get rid of the & ~E_NOTICE

 

Also, is the php.ini that you are looking at the same one that php is using? What does the phpinfo() show for Loaded Configuration File?

 

Edit: There is no setting display errors_on. It's display_errors

Link to comment
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.