Jump to content

Can't Figure Out Insert


Clinton

Recommended Posts

I've been racking my brain for about 2 hours... can't figure out why this isn't inserting into the database?

 

I have verified that num_rows is coming back as 1 so it should be executing it accordingly. My webpage does echo "The End" so it's running through it correctly, it's just not running the INSERT INTO but not giving me a die error.

 

It's the right table, the right everything... I just can't figure it out.

 

if(mysql_num_rows($result)=='1'){
while($row = mysql_fetch_array($result))
{
$uid = $row['id'];
}
$dob = $dobyear . "-" . $dobmonth . "-" . $dobday;
$cred1expire = $year1 . "-" . $month1 . "-" . $day1;
$cred2expire = $year2 . "-" . $month2 . "-" . $day2;
$cred3expire = $year3 . "-" . $month3 . "-" . $day3;
$cred4expire = $year4 . "-" . $month4 . "-" . $day4;
$cred5expire = $year5 . "-" . $month5 . "-" . $day5;
$homephone = preg_replace('/\D+/', '', $homephone);
$cellphone = preg_replace('/\D+/', '', $cellphone);
$dlnumber = preg_replace('/\D+/', '', $dlnumber);
$dayphone = preg_replace('/\D+/', '', $dayphone);
$evephone = preg_replace('/\D+/', '', $evephone);
$oneyear = mktime(0,0,0,date("m"),date("d"),date("Y")+1); 
$annual = date("Y-m-d", $oneyear);
mysql_query("INSERT INTO uinfo (uid,address,city,county,zip,homephone,cellphone,carrier,texts,dob,dlnumber,dlstate,languages,ename,relationship,dayphone,evephone,employer,position,waddress,wcity,wcounty,wzip,emergency,memployer,choice1,choice2,choice3,interest,interestedposition,travel,distance,length,transport,cred1,cred1num,cred1state,cred1expire,cred2,cred2num,cred2state,cred2expire,cred3,cred3num,cred3state,cred3expire,cred4,cred4num,cred4state,cred4expire,cred5,cred5num,cred5state,cred5expire,hear,contract,annual) VALUES ('$uid’,'$address’,'$city’,'$county’,'$zip’,'$homephone’,‘$cellphone’,‘$carrier’,‘$texts’,‘$dob’,‘$dlnumber’,‘$dlstate’,‘$languages’,‘$ename’,‘$relationship’,‘$dayphone’,‘$evephone’,‘$employer’,‘$position’,‘$waddress’,‘$wcity’,‘$wcounty’,‘$wzip’,‘$emergency’,‘$memployer’,‘$choice1’,‘$choice2’,‘$choice3’,‘$interest’,‘$interestedposition’,‘$travel’,‘$distance’,‘$length’,‘$transport’,‘$cred1’,‘$cred1num’,‘$cred1state’,‘$cred1expire’,‘$cred2’,‘$cred2num’,‘$cred2state’,‘$cred2expire’,‘$cred3’,‘$cred3num’,‘$cred3state’,‘$cred3expire’,‘$cred4’,‘$cred4num’,‘$cred4state’,‘$cred4expire’,‘$cred5’,‘$cred5num’,‘$cred5state’,‘$cred5expire’,‘$hear’,‘$contract’,‘$annual’)" or die (mysql_error()));
echo $homephone; ?> The End. <? } else { ?> There has been an error. Please consult your webmaster for assistance. <br> <? }} ?>

Link to comment
https://forums.phpfreaks.com/topic/270688-cant-figure-out-insert/
Share on other sites

I've been racking my brain for about 2 hours... can't figure out why this isn't inserting into the database?

 

I have verified that num_rows is coming back as 1 so it should be executing it accordingly. My webpage does echo "The End" so it's running through it correctly, it's just not running the INSERT INTO but not giving me a die error.

 

It's the right table, the right everything... I just can't figure it out.

 

if(mysql_num_rows($result)=='1'){
while($row = mysql_fetch_array($result))
{
$uid = $row['id'];
}
$dob = $dobyear . "-" . $dobmonth . "-" . $dobday;
$cred1expire = $year1 . "-" . $month1 . "-" . $day1;
$cred2expire = $year2 . "-" . $month2 . "-" . $day2;
$cred3expire = $year3 . "-" . $month3 . "-" . $day3;
$cred4expire = $year4 . "-" . $month4 . "-" . $day4;
$cred5expire = $year5 . "-" . $month5 . "-" . $day5;
$homephone = preg_replace('/\D+/', '', $homephone);
$cellphone = preg_replace('/\D+/', '', $cellphone);
$dlnumber = preg_replace('/\D+/', '', $dlnumber);
$dayphone = preg_replace('/\D+/', '', $dayphone);
$evephone = preg_replace('/\D+/', '', $evephone);
$oneyear = mktime(0,0,0,date("m"),date("d"),date("Y")+1);
$annual = date("Y-m-d", $oneyear);
[code]mysql_query("INSERT INTO uinfo (uid,address,city,county,zip,homephone,cellphone,carrier,texts,dob,dlnumber,dlstate,languages,ename,relationship,dayphone,evephone,employer,position,waddress,wcity,wcounty,wzip,emergency,memployer,choice1,choice2,choice3,interest,interestedposition,travel,distance,length,transport,cred1,cred1num,cred1state,cred1expire,cred2,cred2num,cred2state,cred2expire,cred3,cred3num,cred3state,cred3expire,cred4,cred4num,cred4state,cred4expire,cred5,cred5num,cred5state,cred5expire,hear,contract,annual) VALUES ('$uid’,'$address’,'$city’,'$county’,'$zip’,'$homephone’,‘$cellphone’,‘$carrier’,‘$texts’,‘$dob’,‘$dlnumber’,‘$dlstate’,‘$languages’,‘$ename’,‘$relationship’,‘$dayphone’,‘$evephone’,‘$employer’,‘$position’,‘$waddress’,‘$wcity’,‘$wcounty’,‘$wzip’,‘$emergency’,‘$memployer’,‘$choice1’,‘$choice2’,‘$choice3’,‘$interest’,‘$interestedposition’,‘$travel’,‘$distance’,‘$length’,‘$transport’,‘$cred1’,‘$cred1num’,‘$cred1state’,‘$cred1expire’,‘$cred2’,‘$cred2num’,‘$cred2state’,‘$cred2expire’,‘$cred3’,‘$cred3num’,‘$cred3state’,‘$cred3expire’,‘$cred4’,‘$cred4num’,‘$cred4state’,‘$cred4expire’,‘$cred5’,‘$cred5num’,‘$cred5state’,‘$cred5expire’,‘$hear’,‘$contract’,‘$annual’)" or die (mysql_error()));

echo $homephone; ?> The End. <? } else { ?> There has been an error. Please consult your webmaster for assistance. <br> <? }} ?>
[/code]

 

at the end of your query your () and "" are out of order. Your 'or die' is inside of your query and your "" are messed up. Try this:

 

mysql_query("INSERT INTO uinfo (uid,address,city,county,zip,homephone,cellphone,carrier,texts,dob,dlnumber,dlstate,languages,ename,relationship,dayphone,evephone,employer,position,waddress,wcity,wcounty,wzip,emergency,memployer,choice1,choice2,choice3,interest,interestedposition,travel,distance,length,transport,cred1,cred1num,cred1state,cred1expire,cred2,cred2num,cred2state,cred2expire,cred3,cred3num,cred3state,cred3expire,cred4,cred4num,cred4state,cred4expire,cred5,cred5num,cred5state,cred5expire,hear,contract,annual) VALUES ('$uid’,'$address’,'$city’,'$county’,'$zip’,'$homephone’,‘$cellphone’,‘$carrier’,‘$texts’,‘$dob’,‘$dlnumber’,‘$dlstate’,‘$languages’,‘$ename’,‘$relationship’,‘$dayphone’,‘$evephone’,‘$employer’,‘$position’,‘$waddress’,‘$wcity’,‘$wcounty’,‘$wzip’,‘$emergency’,‘$memployer’,‘$choice1’,‘$choice2’,‘$choice3’,‘$interest’,‘$interestedposition’,‘$travel’,‘$distance’,‘$length’,‘$transport’,‘$cred1’,‘$cred1num’,‘$cred1state’,‘$cred1expire’,‘$cred2’,‘$cred2num’,‘$cred2state’,‘$cred2expire’,‘$cred3’,‘$cred3num’,‘$cred3state’,‘$cred3expire’,‘$cred4’,‘$cred4num’,‘$cred4state’,‘$cred4expire’,‘$cred5’,‘$cred5num’,‘$cred5state’,‘$cred5expire’,‘$hear’,‘$contract’,‘$annual’") or die (mysql_error());

Thanks, folks. I did what you suggested and it still didn't work.

 

Then, I finally figured it out and I feel like putting my head through a wall.

 

My editor was acting screwy so I took the long statement and typed it in a document, so I could see it properly. Well, instead of ' it uses . Oh how that little slant makes all the difference in the world and such a newb mistake. 8-\

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.