Jump to content

Unable to change sql database with php script


jlgray48

Recommended Posts

Here is my code..... I have a database named uah and and a table within uah named yahoo with id and name as fields.

 

<?

$name = "Kim";

$id = "44";

$conn=mysql_connect("127.0.0.1", "odbc", "");

mysql_select_db("uah",$conn);

$sql = "Insert into yahoo values('$id', '$name')";

mysql_query($sql,$conn);

$result = mysql_query($sql,$conn);

 

?>

Someone had sent this code earlier and I used odbc for the username and no password and it works fine.

Also if I type status it has odbc as the username. I'm working ont this for a final and I'm wondering if it is just a case of 2 different versions of php or mysql? I'm getting pretty frustrated at this point.

 

[/code]

<?php

//MySQL information MODIFY IT HERE.

 

$host = "";//Host

$db_name = "";//Database

$db_user = "";//Username

$db_password = "";//Password

 

//Connect to the database

$dbnews = @mysql_connect("$host", "$db_user", "$db_password");

if (!$dbnews)

{

    die("

            <center>Could not connect to MySQL Server($host).

" .

        mysql_error() . "</center>

        ");

}

 

//Select the database

if (!@mysql_select_db("$db_name"))

{

    die("

            <center>Could not select MySQL Database($db_name)

" . mysql_error

        () . "</center>

        ");

}

 

mysql_query("create table yahoo(id int, name char(10), primary key(id))", $link);

?>

 

Try that and see how it works out.

 

 

 

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.