Paulo Rodrigues Paulo Rodrigues - 4 years ago 135
SQL Question

How to insert SESSION_id on table

I need help to insert into my database league using a slash

if(isset($_POST['selecionar']))
{
$queryselect=sprintf("INSERT INTO league
(users_user_id)
VALUES
( '{$_SESSION['user_id']}')",
mysqli_real_escape_string($link, $_POST['selecionar'])
);
mysqli_query($link, $queryselect);


[...]

<form id='alterar_selecionar' method='POST'>
<input type='hidden' name='selecionar' value=<?php echo "'" . $row['id'] . "'"; ?> />
<input type="submit" onClick="return confirm('Tem a certeza que deseja cancelar esta reserva ?')" value='Selecionar' />
</form>


screenshot

Answer Source

I see the question you ask is that you want to insert "league using a slash" into your database. I noticed that the name of your MySQL table is league, and there appears to be a / at the end of your hidden HTML input.

<input type='hidden' name='selecionar' value=<?php echo "'" . $row['id'] . "'"; ?> />

The way I am interpreting this is that you want to insert the ID number and a slash into your MySQL table named league. If I am interpreting this correctly, then I think what you are missing here are single quotes in the value section of your hidden input type. Notice you do have single quotation marks in type='hidden' and name='selectinar' but there are no single quotes around the value. In the following code, I just placed single quotes around the value field.

    <input type='hidden' name='selecionar' value='<?php echo "'" . $row['id'] . "'"; ?> /'>

It might also be helpful to create a variable named $id to help make this PHP a bit easier to comprehend and read.

<?php 
$id = $row['id'];
echo "<input type='hidden' name='selecionar' value='$id/'>";
?>

I still am not sure if I truly understand your objective here, but perhaps something along these lines makes sense.

PHP to get the id and then echo the $id in the HTML form with the /

<?php
$con = new mysqli('ip_or_domain', 'username', 'password', 'db');
$getid = "select id from tablename where something='something' ");
$query = mysqli_query($con, $getid);

while ($row = mysqli_fetch_array($query)) {
$id = $row['id'];
}
?>

<form id='alterar_selecionar' method='POST'>                                          
<input type='hidden' name='selecionar' value='<?php echo $id; ?>/'>
<input type="submit" onClick="return confirm('Tem a certeza que deseja cancelar esta reserva ?')" value='Selecionar' />
</form>

PHP MySQL Insert

<?php
$selecionar = $_POST['selecionar'];
$con = new mysqli('ip_or_domain', 'username', 'password', 'db');
$insert = "insert into league (users_user_id) values ('$selecionar')";
$con->query($insert);
?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download