Jump to content

PHP MySQL Query not going as planned?


MannyG

Recommended Posts

Hey this forum has been very helpful for the questions ive posed over the last few weeks and I have yet another addition of questions I am stumbled on...

 

I am running a query in a variable and using the mysql_query($variableNameOfQuery) to run the query into the database. The query is an update script, which ive tested manually in a MySQL cmd client and on PHPMyAdmin and it run's fine. However when I run the query from PHP it deletes a specific record o__O. There are 4 records I am updating, in 2 tables, and it deletes one of the records that I would like to update, does not replace it, deletes whatever WAS there. Here is what my form page looks like...

 

<body>
<?php
##Connection to Database
$conn = mysql_connect("javasrv19", "", "") or die("Could not connect : " . mysql_error());
mysql_select_db("javaconformance_testproject", $conn) or die("Could not select database");

$Auto_id = $_GET['Auto_id'];

$test = "SELECT build.bundle, devices.devicename, build.version FROM build, devices WHERE ((build.build_id = '$Auto_id') AND (devices.deviceID = '$Auto_id'))"; 
   
   $result = mysql_query($test);
   $row = mysql_fetch_array($result);

echo "<center>";
  echo "<form method='POST' action='editInsert.php'>";
      echo "<h1><b>Edit Results</b></h1></br>";
    echo "<p class='hlight'><b>Codeline</b>";
  echo   "<input type='text' name='codeline' value='".$row['version']."' maxlength='10' size='10'>";
   echo   "</p>";
echo	"<p class='hlight'><b>Bundle</b>";
  echo   " <input type='text' name='bundle' value='".$row['bundle']."' maxlength='10' size='10'>";
  echo    "</p>";
echo	"<p class='hlight'><b>Device</b>";
echo    " <input type='text' name='device' value='".$row['devicename']."' maxlength='10' size='10'>";
echo    " </p>";

   echo   "<input type='submit' name='submit' value='Submit'>";
   echo   "<a href=index.php><button>Cancel</button></a>";
echo " <input type='hidden' name='Auto_id' value = '".$Auto_id."' >";
  echo  "</p>";
  echo  "</form>";

echo	"</center>";

?>
</body>

 

 

And here is the 'editInsert.php' page that this form links too upon submit.

 

<body>
<?php
##Connection to Database
$conn = mysql_connect("javasrv19", "", "") or die("Could not connect : " . mysql_error());
mysql_select_db("javaconformance_testproject", $conn) or die("Could not select database");

##Get Auto_id identifier
$Auto_id = $_POST['Auto_id'];

##Query
$bundle=$_POST['bundle'];
$version=$_POST['codeline'];
$device=$_POST['devicename'];

$sql = "UPDATE build, devices SET build.bundle = '$bundle', build.version = '$version', devices.devicename = '$device', devices.fledgeid = '$device' WHERE ((build.build_id = '$Auto_id') AND (devices.deviceID = '$Auto_id'))" ;
mysql_query($sql);

echo "<br/>";
echo "Record Updated";
echo "<br/>";
echo   "<a href=index.php><button>Go Back</button></a>";
mysql_close();

?>

</body>

Link to comment
https://forums.phpfreaks.com/topic/197762-php-mysql-query-not-going-as-planned/
Share on other sites

I echo'd the query and everything I have been passing displays EXCEPT the two that dissapear...which is odd because as of now i re-added the values to the database so they should show, i have them appearing in the form...

 

so I am a little confused @__@ why is everything showing but these two, they are the exact same values just going into two different spots in the table...o_O

Archived

This topic is now archived and is closed to further replies.

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