PHP/MySQL problem - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP/MySQL problem (/showthread.php?tid=69508)
PHP/MySQL problem by YottabyteWizard on 12-14-2006 at 10:39 PM
I have a problem with some of my first php scripts, hope you can help me out.
I have this really big form (around 200 text fields), so to make things faster and uses the less possible space I'm trying to insert the first text field to a database, then get its ID and start a cycle where the script will keep inserting on each one the information on each text field.
For some reason it's not working.
code:
<?php
error_reporting(E_ALL);
echo "Processing"...
mysql_connect("localhost","username","password") or die(mysql_error());
mysql_select_db("chismografo") or die(mysql_error());
$q = array(5);
for ($cpost=1; $cpost < 6; $cpost++)
{
$q[$cpost]=_POST["T".$cpost];
}
MYSQL_QUERY("INSERT INTO datos (id,q1) VALUES ('NULL', '$q[1]')");
$scriteria=(MYSQL_QUERY("SELECT id FROM `chismografo`.`datos` WHERE q1='$q[1]'"));
for ($postn=2; $postn < 6; $postn++)
{
MYSQL_QUERY("INSERT INTO datos (id,q[$postn]) VALUES ('$scriteria', '$q[$postn]')");
}
echo "Query Finished";
?>
Wohoo, 600th post...
RE: PHP/MySQL problem by WDZ on 12-15-2006 at 05:40 AM
Every INSERT query creates a new row. You can't use it to insert individual values into an existing row. That's what UPDATE is for.
Anyway, these changes will get rid of the parse errors...
echo "Processing"...
echo "Processing...";
$q[$cpost]=_POST["T".$cpost];
$q[$cpost]=$_POST["T".$cpost];
Also, here's another bug fix...
$scriteria=(MYSQL_QUERY("SELECT id FROM `chismografo`.`datos` WHERE q1='$q[1]'"));
$scriteria = mysql_insert_id();
There's more work needed, but I don't want to rewrite the whole script. You should learn from your mistakes...
RE: PHP/MySQL problem by YottabyteWizard on 12-15-2006 at 06:41 AM
lol thanks !! that's everything i needed to know.
|