What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP/MySQL problem

PHP/MySQL problem
Author: Message:
YottabyteWizard
Senior Member
****

Avatar

Posts: 709
Reputation: 23
37 / Male / Flag
Joined: Mar 2005
O.P. PHP/MySQL problem
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...

This post was edited on 12-14-2006 at 10:39 PM by YottabyteWizard.
12-14-2006 10:39 PM
Profile E-Mail PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: PHP/MySQL problem
:-/

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... :p
12-15-2006 05:40 AM
Profile PM Web Find Quote Report
YottabyteWizard
Senior Member
****

Avatar

Posts: 709
Reputation: 23
37 / Male / Flag
Joined: Mar 2005
O.P. RE: PHP/MySQL problem
:O lol thanks !! :D that's everything i needed to know.
12-15-2006 06:41 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On