Jump to content

Building an Dynamic SQL before POST


yanviau

Recommended Posts

Hello i try to explain my situation,

 

I have a dynamic table so i need to build a dynamic radiobutton list and build a dynamic sql req.

First of all i build my table with radio button in a while

 

So the radio button is named rdYanViau ( in the html it's working no prob with that )

$name = $row2['FirstName'].$row2['LastName'];

<input type="radio" name="rd<?php echo $name; ?>" value="1">

<input type="radio" name="rd<?php echo $name; ?>" value="2">

 

And in the same while i build a portion of my dynamic sql like that

$valueDeclare .= $row2['FirstName'].$row2['LastName'].', ';

So in my insert this variable give me the FieldName

 

and in the same while i build my $_POST variable for my sql sentence

$valueRadio .= "'".'".$_POST['."'".'rd'.$row2['FirstName'].$row2['LastName']."'".']."'."', ";

This value is '".$_POST['rdYanViau']."'

 

After that i build my sql with those 2 variables, the problem is when i execute my sql insert where he's supose to insert my rdButton value ... it's insert the string '".$_POST['rdYanViau']."' who give me a 0 in the table, he's not getting the value of '".$_POST['rdYanViau']."' he's inserting the string in the table.

 

Here's the echo of my sql sentence :

INSERT INTO sondage (idSondage, username, idMatch, YanViau, YanViau2, YanViau3) VALUES (NULL , 'admin', '1', '".$_POST['YanViau']."', '".$_POST['YanViau2']."', '".$_POST['YanViau3']."')

 

my echo should look like :

INSERT INTO sondage (idSondage, username, idMatch, YanViau, YanViau2, YanViau3) VALUES (NULL , 'admin', '1', '1', '2', '1')

 

How i can build this dynamic sentence and have the radiobutton value and not the string value ...

 

I hope you can understand my problem.

Yan.

Link to comment
https://forums.phpfreaks.com/topic/216257-building-an-dynamic-sql-before-post/
Share on other sites

I'm pretty sure that there should be nothing wrong with this:

 

mysql_query("INSERT INTO sondage (idSondage, username, idMatch, YanViau, YanViau2, YanViau3) VALUES (NULL, 'admin', '1', {$_POST['YanViau']}, {$_POST['YanViau2']}, {$_POST['YanViau3']})") or die(mysql_error());

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.