473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Update statement won't work on MySQL v5.0 and PHP v2.0

Hi Guys,

I mainly develop my program on a package tool provided by PHP Triad (from a long time ago) and I was running them solely on my notebook with no problem at all.

I have this code that works fine:

[PHP]mysql_query("UPDATE people SET room='$room' WHERE name='$name'",$con);[/PHP]

and when I tranfer it to a server that has a MySQL v5.0 and PHP 2.0 I revised the code because the above statement won't work into:

[PHP]$con = mysql_connect("---","---","---");

if ( mysql_query("UPDATE people SET room='".$_POST['room']."' WHERE name='".$_POST['name']."'",$con) )
{ print "<meta http-equiv='refresh' content='0; url=main.php'>"; }
else
{ print mysql_error(); }[/PHP]

It shows like it's working but the table was not updated. It doesn't work at all. ;-(

Please help and thanks.
Mar 31 '08 #1
6 1896
ronverdonk
4,258 Expert 4TB
Where is your db select statement, e.g.[php]mysql_select_db("db_name",$con)[/php]Ronald
Mar 31 '08 #2
I put it on an include statement at the top of the php file:

[PHP]include 'connect.php';[/PHP]

below is the content of the include file:

[PHP]<?php
$link = mysql_connect("---","---","---") or die("Server is currently busy.");
mysql_select_db("outing", $link) or die("Database is currently busy.");
?>[/PHP]
Mar 31 '08 #3
ronverdonk
4,258 Expert 4TB
You trying to make it hard on us? You'd better make up your mind about what connection string you use. In the include you connect and select using connection $link. Then in the script you do a connect and NO DB SELECT and a query using connection $con.
What is it?
[php]$con = mysql_connect("---","---","---");
$link = mysql_connect("---","---","---") or die("Server is currently busy.");
mysql_select_db("outing", $link) or die("Database is currently busy.");
if ( mysql_query("UPDATE people SET room='".$_POST['room']."' WHERE name='".$_POST['name']."'",$con) )[/php]Ronald
Mar 31 '08 #4
i'm sorry for that, here's the complete code that i revised.

[PHP]<html>
<body>
<?php

$name = trim($_POST['name']);
$room = $_POST['room'];
$vrfy = $_POST['vrfy'];
$cfrm = $_POST['cfrm'];

if ( $vrfy == 'false' )
{ print "<script language='javascript'> history.back(); </script>";
exit; }

if ( strlen($name) == 0 || strlen($room) == 0)
{ if ( strlen($name) == 0 )
{ print "<script language='javascript'>".
" alert('Incomplete information, please select your name on the list.');".
" history.back();".
"</script>"; }
else
{ print "<script language='javascript'>".
" alert('Incomplete information, please select your preferred room on the list.');".
" history.back();".
"</script>"; }
exit; }

if ( $cfrm != 'C' )
{ print "<script language='javascript'>".
" alert('You must confirm your registration.');".
" history.back();".
"</script>";
exit; }

$con = mysql_connect("---","---","---");
mysql_select_db("outing", $con);

if ( mysql_query("UPDATE people SET room='".$room."' WHERE name='".$name."'",$con) )
{ print "<meta http-equiv='refresh' content='0; url=main.php'>"; }
else
{ print mysql_error(); }

?>

</body>
</html>[/PHP]

My UPDATE statement seems to be working fine but there's no actual updating made on the table.

What could be the problem on this.? I tried a simple PHP and MySQL code using PHP Triad but with MySQL v5.0 and PHP v2.0 it just won't work.
Mar 31 '08 #5
ronverdonk
4,258 Expert 4TB
Are you definitely sure that that name exists in a row in the db? Because if it does not, you will not get an error![php]WHERE name='".$name."'",$con) )[/php]Ronald
Mar 31 '08 #6
Thanks for that question Ronald. The row name on the table was a text and the variable $name was txt as well.

I just add an additional field with type TINYINT and make is as my key field and set it to autoincrement and that's do the job.

Thanks again, smart question there.. ;-)
Mar 31 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
6
by: Paul Eden | last post by:
Hello all. I'm totally stumped. Please de-stump me! I've read my data in from the database, changed it according to what i want to do and now I want to write it back. But it seems I can only...
5
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i execute this sql UPDATE tableX SET...
5
by: jayson_13 | last post by:
Hi, I need to implement a counter and i face problem of locking so hope that u guys can help me. I try to do test like this : 1st connection SELECT * FROM nextkey WHERE tblname = 'PLCN'...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
3
by: Tania | last post by:
Hi. I´ve a problem. I have two diffrent databases. And I want to update database B with database A. But when a column is missing in the B it won´t be insert with the update of A. Whole tables...
0
by: David Linsin | last post by:
I created a simple test case to reproduce the problem (also check Bug #15500): import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;...
5
by: Slavan | last post by:
I have an update statement that I'm executing against Oracle database from my C# code and it won't work. UPDATE MenuCaptions SET Caption = N@Caption WHERE MenuId = @MenuId AND CultureId =...
0
by: silversubey | last post by:
I am trying to convert mssql triggers to mysql. I am very new to Mysql and would like some help with my code. My queries work but there has to be a more efficient way to write them. I would greatly...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.