Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-04-16, 03:32 AM
Member
 
Join Date: Mar 2006
Posts: 32
shams
Exclamation php-mysql code doensn't work?

hi
this is php conde for enter values to the mysql table:
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$query="INSERT INTO student4 VALUES (NULL, "zubair", "second", 500)";

$rt=mysql_query($query);
echo mysql_error();

if($rt){echo " Command is successful ";}
else {echo " Command is not successful ";}
?>
</html>
</body>
this is the student4 table with previous entry:
mysql> select * from student4;
+----+---------+-------+------+
| id | name | class | mark |
+----+---------+-------+------+
| 1 | shakeel | first | 500 |
+----+---------+-------+------+
1 row in set (0.08 sec)
any help please?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2006-06-16, 05:20 PM
Junior Member
 
Join Date: Nov 2004
Posts: 13
Deus_m1k3
Default

As far as I can read everithin' I think it's ok, but why don't U try another approach??

$conection= @mysql_connect($server,$user,$pass) or die("Error [0.0]: ". mysql_error()." <br>");
@mysql_select_db($database,$conection) or die("Error [0.1]: ". mysql_error());

$sql_ins = "INSERT INTO student4 VALUES ('', "zubair", "second", 500)";
mysql_query ($sql_ins) or die ("Error [1]: ".mysql_error ());

or

$sql_ins = "INSERT INTO student4 VALUES (, "zubair", "second", 500)";
mysql_query ($sql_ins) or die ("Error [1]: ".mysql_error ());

If the id field is auto_incremet & also PK you shouldn't force it to NULL it'll create inconsistent data, hope this could help

READ YA
Reply With Quote
  #3 (permalink)  
Old 2006-07-04, 05:32 PM
Member
 
Join Date: Jun 2006
Posts: 55
flann is on a distinguished road
Default

I've gotten in the good habit of always listing the fields that I want to insert into, this practice eliminates a lot of bugs.

PHP Code:
INSERT INTO table (field1field2field3)
       
VALUES ('$var1''$var2''$var3'); 
__________________
flann
Free Mortgage Calculator | Debt Free
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:21 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.