Forum Moderators: coopster

Message Too Old, No Replies

How can I?

Update multiple records?

         

nabilino

2:58 am on Nov 3, 2007 (gmt 0)

10+ Year Member



Hey guys,
OK, I want to update multiple records on a table. so, when I go to my EditRecord form I want to be able to edit recrods that are already there and be able to hit the :Edit: button and see changes on my Database.
here is what I have but it's not working:
$query = "UPDATE student SET
(stu_id='$stu_id' And f_name='$f_name'And l_name='$l_name'And phone='$phone')";
@mysql_select_db($database)

Help!

Thank you

ayushchd

6:06 am on Nov 3, 2007 (gmt 0)

10+ Year Member




$query = "UPDATE student SET
(stu_id='$stu_id' And f_name='$f_name'And l_name='$l_name'And phone='$phone')";
@mysql_select_db($database)

I can see lots many problems. I am discussing them below :

I dont think the way you are establishing your database connection is correct.
Here is how you should do it and also it is better to establish the connection before you execute any query...generally we make a single file for databse connection and include it in every other file at the top of the page.

$dbc = mysql_connect("server", "user", "password");
if (!$dbc) {
echo ' Cannot connect to the database because ' . mysql_error();
}
mysql_select_db('databasename', $dbc);
if (!mysql_select_db('databasename')) {
echo ' Cannot select the database because ' . mysql_error();
}

And also, your query doesnt look too good to me, make it this way.

$query = "UPDATE student SET stu_id='$stu_id', f_name='$f_name', l_name='$l_name' AND phone='$phone';";

Lastly you aren't exexuting this query anywhere. Do this
if (!mysql_query($query)) {
echo mysql_error();
}

I hope on correcting all the above, it should work.

nabilino

4:46 am on Nov 4, 2007 (gmt 0)

10+ Year Member



Thank you, That worked...however, it display a wierd error message:
The Query is UPDATE student SET stu_id='0001', f_name='dfes', l_name='dfrwe' AND phone='2342342432';query error: Truncated incorrect DOUBLE value: 'dfrwe'
you guys have any idea what that is?
thanks

Habtom

5:14 am on Nov 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$query = "UPDATE student SET stu_id='$stu_id', f_name='$f_name', l_name='$l_name' AND phone='$phone';";

To:

$query = "UPDATE student SET stu_id = '$stu_id', f_name = '$f_name', l_name='$l_name', phone='$phone'";

nabilino

12:48 pm on Nov 4, 2007 (gmt 0)

10+ Year Member



Still the same error message comes up...

Habtom

12:56 pm on Nov 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What does your current code look like?

ayushchd

1:02 pm on Nov 4, 2007 (gmt 0)

10+ Year Member



What are your field data types like?

nabilino

2:32 am on Nov 5, 2007 (gmt 0)

10+ Year Member



Here is what my code look like:
<?php
$stu_id=$_POST["stu_id"];
$f_name=$_POST["f_name"];
$l_name=$_POST["l_name"];
$phone=$_POST["phone"];
$host= 'localhost';
$user = '*****';
$passwd = '*******';
$database = '******';
$connect = @mysql_connect($host, $user, $passwd)
or die("connect error: " . mysql_error());
$table_name = 'student';
$query = "UPDATE student SET stu_id = '$stu_id', f_name = '$f_name', l_name='$l_name', phone='$phone'";
@mysql_select_db($database)
or die('select_db error: ' . mysql_error());
print "The Query is <span class=\"c2\">$query</span><br /><br />";
@mysql_query($query, $connect)
or die('query error: ' . mysql_error());
print '<span class="c1">';
print "Insert into $database was successful!</span>";
@mysql_close ($connect) or die('close error: ' . mysql_error());
?>

</body>
</html>

Caliber Mengsk

3:40 am on Nov 5, 2007 (gmt 0)

10+ Year Member



"Truncated incorrect DOUBLE value" tells you what your problem is.
l_name is set to the DOUBLE type inside of your sql server, and you are sending a string (aka varchar , text, or longtext to it)

Change the l_name type to one of the string types. (if varchar, don't forget that you can set your string to a limited amount, anywhere from 1 to anywhere under 255 charactors in length. This is the best choice for usernames, email, first/last name, etc that won't be long to save space.)

Hope that helps you. If that's not the issue, just reply.